Powered by Blogger.

Saturday, March 1, 2014

How to send GridView row data to the next page using Hyperlink in ASP.net




In this post i explain how to send or pass girdview row value to the next page using hyperlink.      
   Steps to do:
   1. Add hyperlink column in the gridview control.
   2. Set the data fields to navigate to the next page in the DataNavigateUrlFields property of the hyperlink field.
   3. Pass Query String value in  DataNavigateUrlFormatString property of the hyperlink field.
   4. Retreve data in the 2nd page using Request.QueryString.      

 Source page of Default.aspx:
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns  ="False" DataSourceID="SqlDataSource1">
 <Columns>
       <asp:HyperLinkField DataNavigateUrlFields="empid,empname,empadd" DataNavigateUrlFormatString="Default2.aspx?empid={0}&empname={1}&empadd={2}" Text= "sendData" />
        <asp:BoundField DataField ="empid" HeaderText="empid" SortExpression="empid" />
        <asp:BoundField DataField="empname" HeaderText="empname"                  SortExpression="empname" />
        <asp:BoundField DataField="empadd" HeaderText="empadd"  SortExpression="empadd" />
 </Columns>
 </asp:GridView>
  <asp:SqlDataSource ID="SqlDataSource1" runat="server"
   ConnectionString="<%$ ConnectionStrings:abithaConnectionString %>"
   SelectCommand="SELECT * FROM [emp]"></asp:SqlDataSource>

Source page of Default2.aspx:

   EmployeeID:
        <asp:Label ID="lblEmpId" runat="server"></asp:Label>

   EmployeeName:
        <asp:Label ID="lblEmpName" runat="server"></asp:Label>
     
   EmployeeAddress:
        <asp:Label ID="lblEmpAddress" runat="server"></asp:Label>
Code behind page of Default2.aspx:

Protected void Page_Load( sender As Object, e As System.EventArgs)
{
        String strid ;
        String strname;
        String stradd;
        strid = Request.QueryString("empid");
        strname = Request.QueryString("empname");
        stradd = Request.QueryString("empadd");
        lblEmpId.Text = strid;
        lblEmpName.Text = strname;
        lblEmpAddress.Text = stradd;
}



0 comments

Post a Comment