0

So the problem I have is being able to get the value from the <asp:buttonfield /> I am using now and running a query based on this.
I want when I postback to have a sql query and a gridview generated based on the string passed from the button click.
example:

<asp: Panel ID="Option1" runat="server" Visible="False">
        
                    <asp: GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                DataSourceID="SqlDataSource1" 
                EmptyDataText="There are no data records to display." 
                onselectedindexchanged="GridView1_SelectedIndexChanged">
                <Columns>
                    <asp: ButtonField DataTextField="Option1" />            
     

                </Columns>
            </asp: GridView>
            
            
            
            
            <asp: SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings: DB1ConnectionString1 %>" 
                ProviderName="<%$ ConnectionStrings: DB1ConnectionString1.ProviderName %>" 
                SelectCommand="SELECT distinct [Option1] FROM [Tablename]">
            </asp: SqlDataSource>
        </asp: Panel>




/* I want to be able to run a query based on the data passed in from the buttonfield eg:

If the value is "Peter"
I want to be able to generate and run a query based on that.
(As it sits I cant even figure out how to get the value from the buttonfield)

*/
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
/* 
expected code 
1) read the value from the button field
2) set an sql query using that value as the where qualifier
3) Bind the data output to another gridview

*/
  
    }

I really appreciate any help or pointers I can get as this is my first week with .net and c# all the help I can get is truly welcome.

Edited by peter_budo: Correcting code tags, closing tag is [/code]

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by becraig
0

I am sorry, I don't understand what you want, It would help if the code was tagged properly.

0

you can create an ItemTemplate..
in which you can setup your button with
CommandName & CommandArgument..

and finally grab the button value at
RowCommand Event..

e.CommandArgument will provide you the required value which you are supplying
via command button

hope that helps..

0

I did find a solution for this using a similar concept will post shortly.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.