I am using one ButtonField in Gridview1.If i click that buttonfield it will be fill the next gridview2.

So i am using rowcommand for this purpose
if (e.CommandName == "nextgrid")
string orderid = Convert.ToString(e.CommandArgument);

fillgrid is the fun to fill second grid.here this orderid takes just row value only that is 1 or 2 not its original value like ID1234.

if i am using this in row command
string orderid = Convert.ToString(grdorders.DataKeys[e.RowIndex].Value);

I got the error "Error GridViewCommandEventArgs' does not contain a definition for 'RowIndex'

Where i can use this RowIndex or any other way to get this buttonfield value and use this value to fill second grid.

10 Years
Discussion Span
Last Post by nandhinijp

I think you need to populate the second grid by clicking a button in a gridrow.I have made Button Type=Button and you can change either to Link type/Image type according to your requirement.


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Style="z-index: 100;
            left: 211px; position: absolute; top: 213px" OnRowDataBound="GridView1_RowDataBound"  OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
             <asp:BoundField DataField="ProductID"></asp:BoundField>
              <asp:BoundField DataField="ProductName"></asp:BoundField>
                <asp:BoundField DataField="SupplierID">
                 <asp:CommandField ButtonType="Button" ShowSelectButton="True" />


protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

    GridViewRow row = GridView1.SelectedRow;
    int supplierID = Convert.ToInt32(row.Cells[2].Text);


In this case i am retreving the supplierID to populate the other grid.

Good Luck.

Edited by mike_2000_17: Fixed formatting

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.