【问题标题】:c# GridView RowDataBound Errorc# GridView RowDataBound 错误
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-06
    • 1970-01-01
    • 2014-08-30
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多