【发布时间】:2011-07-04 09:17:46
【问题描述】:
我有一个gridview,当点击一行时它应该是可编辑的。此网格视图可连续单击,因此当我单击它时,出于编辑原因,该行将显示在其他页面中。我遇到了这样的错误
指定的参数超出了有效值的范围。 参数名称:索引。
这条线正在发生这种情况:
LinkButton _singleClickButton = (LinkButton)e.Row.Cells[1].Controls[1];
我该如何解决这个问题?
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Get reference to button field in the gridview.
LinkButton _singleClickButton = (LinkButton)e.Row.Cells[1].Controls[1];
string _jsSingle = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "Select$" + e.Row.RowIndex);
e.Row.Style["cursor"] = "hand";
e.Row.Attributes["onclick"] = _jsSingle;
}
}
}
【问题讨论】:
-
它是什么?控件[0] 还是控件[1]?
-
你怎么觉得是
Control[1],难道你不能不用FindControl -
@V4Vendetta 我最初使用 Control[0] 但不起作用。 FindControl怎么用,能不能扔一些样片?谢谢:D
-
@Edwin 第一个。仍然像以前一样出现错误
标签: c# gridview rowdatabound