Thursday, 15 August 2013

Gridview onRowCommand fired gridview no data

Gridview onRowCommand fired gridview no data

<asp:GridView ID="gvWorkshop" runat="server"
AllowCustomPaging="True" AllowPaging="True"
BorderStyle="Solid" BorderWidth="1px"
AllowSorting="True" AutoGenerateColumns="False"
DataKeyNames="ID, ctrycode"
OnRowCommand="gvWorkshop_onRowCommand">
<Columns>
<asp:ButtonField CommandName="Select" Text="Select" />
<asp:BoundField DataField="paddress" HeaderText="Address" />
</Columns>
</asp:GridView>
Code Behind
protected void gvWorkshop_onRowCommand(object sender,
GridViewCommandEventArgs e)
{
int index;
string ID;
GridViewRow row;
if(e.CommandName == "Edit")
{
index = Convert.ToInt32(e.CommandArgument);
row = gvWorkshop.Rows[index];
ID = gvWorkshop.DataKeys[grdrow.RowIndex]["workshopID"].ToString();
}
}
I get error index out of range because the gridview is empty. Any one has
idea whats go wrong? WHy the gridview become empty. Please help.

No comments:

Post a Comment