How to pass code behind variable via hyperlinkfield

.net, asp.net, c#, hyperlink

Solution

You can pass navigation URL from code behind also like this

In Aspx Page

              <asp:TemplateField>
                    <ItemTemplate>
                        <asp:HyperLink ID="hyp" runat="server" Text="Navigation"></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>    

In Code behind User grid view data bound event like this

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 +"";
        }
    }

i think this will help you...

Problem

This is my code behind in C# . ``` protected void Page_Load(object sender, EventArgs e) { Name = "Nitin"; } ``` I have a GridView in which there is a Hyperlinkfield.I want to send `Name` from C# page(one in code behind) to next page via HyperLinkField but it is not one of the BoundField's of the GridView(i.e. Which I get from EntityDataSource). This is my asp.net code. code: ``` <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> ```

Original source