Passing QueryString from asp.net hyperlink in asp.net using c#

In this asp.net tutorial you will learn how to pass QueryString from asp.net hyperlink in asp.net using c#. Let's have a look over how to do this. In first example we will look how to pass single QueryString from asp.net hyperlink and then in second example we will look how to pass multiple QueryString params from asp.net hyperlink.

First Example:-

<asp:TemplateField HeaderText="Case No">

<ItemTemplate>

<asp:HyperLink ID="hyp_Caseno" Text='<%# Bind("Case_No")%>' runat="server" NavigateUrl='<%# "yourpage.aspx?caseno=" + DataBinder.Eval(Container.DataItem,"Case_No")%>'></asp:HyperLink>

</ItemTemplate>

</asp:TemplateField>

Note:- The Case_No in DataBinder.Eval is the column name of your database’s table. Actually we are getting values of the column from database’s table whenever grid will bind.

Now let’s have a look over how to pass multiple QueryString Params from asp.net hyperlink

Second Example:-

<asp:TemplateField HeaderText="Case No">

<ItemTemplate>

<asp:Hyperlink ID="hyp_Caseno" Text='<%# Bind("Case_No")%>' runat="server" NavigateUrl='<%# "yourpage.aspx?caseno=" + DataBinder.Eval(Container.DataItem,"Case_No") + "&productid=" + DataBinder.Eval(Container.DataItem,"Product_ID")%>' />

</ItemTemplate>

</asp:TemplateField>

So this is the way to pass single and multiple QueryString params from asp.net hyperlink.

Happy Coding

Keep Coding

0 comments: