Pass multiple values in single QueryString using LinkButton in ASP.Net GridView using C#

chetan
 
on Feb 16, 2018 02:31 AM
Sample_141703.zip
3621 Views

 

<ItemTemplate>
<asp:LinkButton ID="Link" runat="server" PostBackUrl='<%#"~/expo_crm/invoice/payment_receipt.aspx?id="+Eval("Sno")%>'>View</asp:LinkButton>
</ItemTemplate>

I know this is a basic question but i always had problems with session and querystrings.In postbackurl,i wanted to pass invoiceid value to payment receipt webform.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
nagaraju60
 
on Feb 16, 2018 02:45 AM
on Feb 16, 2018 02:48 AM

Dear @chetan, 

<asp:LinkButton ID="LinkButton1" PostBackUrl='<%# "printpayslip.aspx?empcode=" + Eval("EmpCode") +"&Month="+ Eval("month")  %>' runat="server">print</asp:LinkButton>

please refer below 

http://www.aspforums.net/Threads/458233/Pass-Multiple-QueryString-Values-in-GridView-to-another-Page-using-LinkButton-or-HyperLink-in-ASPNet/

 

dharmendr
 
on Feb 16, 2018 02:46 AM

Hi chetan,

Check this example. Now please take its reference and correct your code.

HTML

CS.aspx

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField DataField="Id" HeaderText="Id" />
        <asp:BoundField DataField="Name" HeaderText="Name" />
        <asp:BoundField DataField="Country" HeaderText="Country" />
        <asp:TemplateField HeaderText="View">
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl='<%# Eval("Id", "~/DetailsCS.aspx?Id={0}") %>'>
                    View</asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Code

CS.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        System.Data.DataTable dt = new System.Data.DataTable();
        dt.Columns.AddRange(new System.Data.DataColumn[3] { 
            new System.Data.DataColumn("Id"), new System.Data.DataColumn("Name"), new System.Data.DataColumn("Country") });
        dt.Rows.Add("1,5,6", "John Hammond", "United States");
        dt.Rows.Add("2", "Mudassar Khan", "India");
        dt.Rows.Add("3", "Suzanne Mathews", "France");
        dt.Rows.Add("4", "Robert Schidner", "Russia");
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
}

DetailsCS.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["Id"]))
        {
            Response.Write("Id is: <b>" + Request.QueryString["Id"] + "</b>");
        }
    }
}

Screenshot