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.

Recommended Answers

All 2 Replies

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.

Thank u .Its working.

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.