我使用以下代码获取行索引
protected void gvESAPending_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
lblMsg.Text = "";
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvESAPending.Rows[index]; // Here incorrect format error is coming
}
}
但索引值为0.这里有什么问题?
Aspx代码
“> “>
答案 0 :(得分:1)
您可以添加OnRowCreteEvent
ASPX:
<asp:gridview id="gvESAPending" onrowcreated="gvESAPending_RowCreated" ...
CS:
protected void gvESAPending_RowCreated(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton addButton = (LinkButton)e.Row.Cells[0].Controls[0];
addButton.CommandArgument = e.Row.RowIndex.ToString();
}
}
答案 1 :(得分:0)
GridViewRow row = gvESAPending.Rows[index];
通过执行此操作,您实际访问索引处的行。因此,如果index = 2,则实际返回gridviewrow中的第三行。