我在页面上创建咯一个Gridview,并且为其添加一个新列,(类型HyperLinkField)
现在有一个问题是,我在后台如何为这个新列动态添加超级连接(DataNavigateUrlFormatString)

解决方案 »

  1.   

    用脚本也可以实现啊
    html
    function winopen(param)
    {
      ......连接页
    }
    HyperLinkField.Attributes.Add("onclick", "winopen('43433')");
      

  2.   

    有难度么?没看出来..........ItemDataBound的时候赋值不行?
      

  3.   

    说错了,是RowDataBound 事件.从第2个参数的Row 属性中获取对该行的引用,然后得到你需要的参数,再赋值就行了
      

  4.   

    可以在ROWCREATED事件中指定。
        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType = DataControlRowType.DataRow)
            {
                ...do..
            }
        }
      

  5.   

    我想知道Gridview的超级连接是那个参数?
      

  6.   

    <asp:TemplateField>
                                    <ItemTemplate>
                                       <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "~/SystemManager/EmployeeQuery/UserSettingEdit.aspx?id="+Eval("EmployeeID") %>'>编辑用户设置</asp:HyperLink>                                </ItemTemplate>
                                </asp:TemplateField>
      

  7.   

    谢谢楼上,
    我的意思是在.CS页面如何引用?
    比如我在前台定义咯一个超级连接
    <asp:HyperLink ID="HyperLink1" runat="server">HyperLink</asp:HyperLink>那么我可以在后台这么引用
            HyperLink1.Text = "asdbad";我现在碰到的问题是
    我在页面上创建咯一个Gridview,并且为其添加一个新列,(类型HyperLinkField)
    如何在后台如何为这个新列动态添加超级连接(DataNavigateUrlFormatString)
      

  8.   

    <asp:TemplateField>
                                        <ItemStyle HorizontalAlign="Center" />
                                        <ItemTemplate>
                                            <asp:HyperLink ID="HyperLinkEdit" runat="server" NavigateUrl='<%# Eval("SingerID", "SingerEdit.aspx?SingerID={0}") %>'
                                                Text="编辑"></asp:HyperLink>
                                        </ItemTemplate>
                                    </asp:TemplateField>
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string SingerID = GridView1.DataKeys[e.Row.RowIndex][0].ToString();
                try
                {
                    HyperLink HyperLinkEdit = (HyperLink)e.Row.FindControl("HyperLinkEdit");
                    HyperLinkEdit.NavigateUrl = "SingerEdit.aspx?SingerID=" + SingerID + "&sex=" + strsex;
                }
                catch
                {
                }
            }
        }