c#GridView RowDataBound错误

时间:2011-07-04 09:17:46

标签: c# gridview rowdatabound

我有一个gridview,在单击一行时应该可以编辑。此gridview可以连续单击,因此当我单击它时,该行将显示在其他页面中以进行编辑。我收到了这样的错误

  

指定的参数超出了有效值的范围。   参数名称:index。

这一行正在发生:

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;
        }
    }  
}

1 个答案:

答案 0 :(得分:0)

您应该使用e.Row.FindControl("linkbuttonid")之类的内容。这将从当前行获取所需的链接按钮,然后您可以将处理程序附加到相同的位置并执行逻辑

相关问题