如何通过超链接字段在变量后面传递代码

Nit*_*ari 5 .net c# asp.net hyperlink

这是我在C#中的代码.

protected void Page_Load(object sender, EventArgs e)
    {
           Name = "Nitin";                      
    } 
Run Code Online (Sandbox Code Playgroud)

我有一个GridView,其中有一个Hyperlinkfield.我想Name通过HyperLinkField从C#页面(后面的代码中的一个)发送到下一页,但它不是GridView的BoundField之一(即我从EntityDataSource获得的).这是我的asp.net代码.

代码:

   <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="WorkItemsEntityDataSource">
    <Columns>
        <asp:hyperlinkfield datatextfield="Id"                    
                datanavigateurlfields="Id"
                datanavigateurlformatstring="~\WorkItems.aspx?Id={0}"          
                headertext="Id"/> 
        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
        <asp:BoundField DataField="TFSId" HeaderText="TFSId" SortExpression="TFSId" />
        <asp:CheckBoxField DataField="IsBillable" HeaderText="IsBillable" SortExpression="IsBillable" />
    </Columns>
</asp:GridView>
Run Code Online (Sandbox Code Playgroud)

Raj*_*hit 4

您也可以像这样从代码后面传递导航 URL

在 Aspx 页面中

              <asp:TemplateField>
                    <ItemTemplate>
                        <asp:HyperLink ID="hyp" runat="server" Text="Navigation"></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>    
Run Code Online (Sandbox Code Playgroud)

在用户网格视图数据绑定事件后面的代码中,如下所示

protected void grddata_RowDataBound(object sender, GridViewRowEventArgs e)
    {    
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int ID = Convert.Int32(DataBinder.Eval(e.Row.DataItem, "ID"));
            HyperLink hyp = (HyperLink)e.Row.FindControl("hyp");
            hyp.NavigateUrl = "Test.aspx?Name='" + Request.QueryString["test"] + "'&&ID"+ ID +"";
        }
    }
Run Code Online (Sandbox Code Playgroud)

我想这会对你有帮助...