【问题标题】:Specified argument was out of the range of valid values - RowDataBound指定的参数超出了有效值的范围 - RowDataBound
【发布时间】:2015-10-15 04:58:41
【问题描述】:

我想更改行数据绑定事件中的导航 url 属性。如果该列未与链接绑定我想添加导航 url= #

<asp:TemplateField HeaderText="Reportd Link"  ItemStyle-HorizontalAlign="center" >
                    <ItemTemplate>
                   <asp:HyperLink ID="Lbl_RptLnk1" runat="server" NavigateUrl='<%#Eval("ReportLinks")%>'
                            Text='Reported Link' Target="_blank" ToolTip='<%#Eval("ReportLinks")%>'></asp:HyperLink>

                 </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>

aspx.cs 代码

  if (e.Row.RowType == DataControlRowType.DataRow)
    {
        HyperLink myLink = (HyperLink)e.Row.Cells[4].Controls[0];//slno,linkname,linkid,link

        if (myLink.NavigateUrl == "Waiting for Approval")
        {
            myLink.NavigateUrl = "#";
        }

    }

出现错误提示 - 指定的参数超出了有效值的范围。 参数名称:索引

【问题讨论】:

  • 如果是添加runat="server",使用asp.net按钮控件
  • 使用 asp 按钮时出错...类型“System.Web.UI.WebControls.Button”没有名为“ItemStyle”的公共属性。
  • 如果你想使用Button,那么它应该在&lt;asp:TemplateField /&gt;里面,你可以将ItemStyle子应用到那个字段,而不是Buttonmsdn.microsoft.com/en-us/library/bb288032.aspx
  • 也请分享您的Gridview 标记。

标签: c# asp.net gridview


【解决方案1】:

RowDataBound事件中,由于你的控件是TemplateField里面的一个ASP服务器控件,你可以使用行上的FindControl方法找到该控件:-

HyperLink Lbl_RptLnk1 = (HyperLink)e.Row.FindControl("Lbl_RptLnk1");
if (Lbl_RptLnk1.NavigateUrl.Trim() == "Waiting for Approval")
{
     Lbl_RptLnk1.NavigateUrl = "#";
}

【讨论】:

  • 是的,按钮创建问题。所以我用超链接代替。 runat server 和 onclick 一次不工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多