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.

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

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..

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.