How to pass a code for a variable through a hyperlink

This is my C # code.

protected void Page_Load(object sender, EventArgs e)
    {
           Name = "Nitin";                      
    } 

I have a GridView in which there is Hyperlinkfield. I want to send Namefrom a C # page (one per code) to the next page via HyperLinkField, but this is not one of the BoundField GridView (that is, which one I get from EntityDataSource). This is my asp.net code.

the 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>
+5
source share
4 answers

You can also pass a navigation url from code located just like that.

On the Aspx page

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

In the field "Code for binding to user grid data", as shown

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 ...

+2
source

, , URL- QueryString 'Name'. :

~\WorkItems.aspx?Id={0}&Name={1}

Id Name, Id :

~\WorkItems.aspx?Name={0}

- , . , , Id ().

UPDATE

Name , , Name, - , ( , ). :

~\WorkItems.aspx?Id={0}&Name=<%= Name %>
0

:

<asp:TemplateField HeaderText="test">
     <ItemTemplate>
           <asp:HyperLink runat="server" ID="temp" NavigateUrl='<%# String.Format("~\WorkItems.aspx?Id={0}&Name={1}",  Eval("Name"), Name)%>' ></asp:HyperLink>
      </ItemTemplate>
</asp:TemplateField>
0

URL HyperLinkField, :

protected void pendingAccountsGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        ((HyperLink) e.Row.Cell[0].Controls[0]).NavigateUrl = "http://stackoverflow.com";
    }
}

, e.Row.Cell[0].

0

All Articles