我试图在超链接字段中添加到导航网址。
我的gridview上有5列,最后一列是
<asp:HyperLinkField DataNavigateUrlFields="vID"
DataNavigateUrlFormatString="Page2.aspx?field={0}" HeaderText="send"
Text="send"></asp:HyperLinkField>
以及添加到其后面的代码
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim hk As HyperLink = DirectCast(e.Row.Cells(4).Controls(0), HyperLink)
hk.NavigateUrl += "&TN=table1"
End Sub
我昨天有工作,但必须不小心删除了代码,我无法在这里找到错误的地方,我收到错误“指定的参数超出了有效值的范围。 参数名称:索引“
答案 0 :(得分:1)
您必须检查RowType
,否则您也会在标题中查找HyperLink
。
VB
Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs )
If e.Row.RowType = DataControlRowType.DataRow Then
Dim link = DirectCast(e.Row.Cells(4).Controls(0), HyperLink)
link.NavigateUrl &= "&TN=table1"
End If
End Sub
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink link = (HyperLink)e.Row.Cells[4].Controls[0];
link.NavigateUrl += "&TN=table1";
{
}