Pass Multiple Values from ASP.Net GridView to another Page using HyperLink

Last Reply 2 months ago By pandeyism

Posted 2 months ago

How to Pass Multiple Values from a GridView to Another Page using ASP.NET

        <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EmpString %>"
            SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [Address], [City] FROM [Customers]">
        </asp:SqlDataSource>   
        </div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID"
            DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True">
            <Columns>           
                 <asp:HyperLinkField DataNavigateUrlFields="CustomerID"
                    DataNavigateUrlFormatString="CustomerDetails.aspx?CID={0}"
                     Text="Pass Single Value" />
                   <asp:HyperLinkField DataNavigateUrlFields="CustomerID, CompanyName, ContactName, Address, City"
                    DataNavigateUrlFormatString="CustomerDetails.aspx?CID={0}&CName={1}&ContactName={2}&Addr={3}&City={4}"
                      Text="Pass Multiple Values" />
                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
                <asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />
                <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
            </Columns>
            <asp:HyperLink runat="server">HyperLink</asp:HyperLink>
        </asp:GridView>

 

namespace passvalue
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string cid = Request.QueryString["CID"];
            string cname = Request.QueryString["CName"];
            string contactName = Request.QueryString["ContactName"];
            string address = Request.QueryString["Addr"];
            string city = Request.QueryString["City"];
        }
    }
}

 

You are viewing reply posted by: pandeyism 2 months ago.