<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>
代码背后
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();
}
}
我得到错误索引超出范围,因为 gridview 是空的。有人知道出了什么问题吗?为什么gridview变成空的。请帮忙。