Pass Send GridView Row Value/Data Using Hyperlink In ASP.NET

In this example i am describing how to Pass Transfer Or Send GridView Row Data Values To Other asp.net page using hyperlink.

Pass Transfer Send GridView Row Data Values With Hyperlink
I've put a hyperlink column in gridview to pass values through querystring, and using request.querystring on the second page to retrieve values.

You would also like to read
LinkButton in GridView and QueryString in ASP.NET to pass data


We need to set DataNavigateUrlFields and DataNavigateUrlFormatString properties of hyperlink in gridview to pass the row data 
HTML markup of the page


<asp:GridView ID="GridView1" runat="server" 
              AutoGenerateColumns="False" 
              DataSourceID="SqlDataSource1">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="ID,Name,Location" 
DataNavigateUrlFormatString=
"Default2.aspx?id={0}&name={1}&loc={2}" 
Text="Transfer values to other page" />
<asp:BoundField DataField="ID" HeaderText="ID" 
                SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" 
                SortExpression="Name" />
<asp:BoundField DataField="Location" HeaderText="Location" 
                SortExpression="Location" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [ID], [Name], [Location] FROM [Details]">
</asp:SqlDataSource>

Now write code mentioned below to retrieve values on Default2.aspx page
C# code behind
protected void Page_Load(object sender, EventArgs e)
    {
        string strID = Request.QueryString["id"];
        string strName = Request.QueryString["name"];
        string strLocation = Request.QueryString["loc"];
        lblID.Text = strID;
        lblName.Text = strName;
        lblLocation.Text = strLocation;
    }
VB.NET code behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim strID As String = Request.QueryString("id")
    Dim strName As String = Request.QueryString("name")
    Dim strLocation As String = Request.QueryString("loc")
    lblID.Text = strID
    lblName.Text = strName
    lblLocation.Text = strLocation
End Sub

Hope this helps


If you like this post than join us or share

24 comments:

Anonymous said...

please, can you post the whole source code in vb.net with the asp.net pages


James praker said...

This comment has been removed by a blog administrator.


Unknown said...

This comment has been removed by a blog administrator.


Unknown said...

IN THIS HOW TO CREATE HYBERLINK IN FIRST COLUMN(REFERENCE NO.).WHILE CLICKING HAVE TO OPEN NEW ASP PAGE. GIVE ME THE SOLUTION.(ASP.NET 2005 AND SQL SERVER 2005)



Private Sub dataload()
Dim i As Integer
i = 0
Dim constr As String = "Data Source=muru\server2005;Initial Catalog=mis;User Id=sa;Password=professional2005;Integrated Security=False"
Dim objconnection As New SqlConnection(constr)
objconnection.Open()
Dim sqlstr As String = "SELECT NO AS REFNO,DATE,RONO,RODT,CLIENT,FDATE,TDATE,AMOUNT FROM RO07_08 ORDER BY DATE,CLIENT"
Dim ds As New DataSet
Dim da As SqlDataAdapter = New SqlDataAdapter(sqlstr, objconnection)
da.Fill(ds, "ro07_08")
If ds.Tables(0).Rows.Count = 0 Then Exit Sub
dgv.DataSource = ds.Tables(0).DefaultView

dgv.DataBind()
objconnection.Close()
da.Dispose()
da.Dispose()
sqlstr = ""

End Sub


sparky said...

Hi Friend this works great I was seaching from long time on net thanks for this code I am making a forum will use it in this but still I want a code that when people reply to question the replied question gets posts below answer
any reply or help appreciated
thanks a lot


Anonymous said...

thanks you


Anonymous said...

Thanks it works for me.....


Anonymous said...

This comment has been removed by a blog administrator.


Anonymous said...

I love this site csharpdotnetfreak.blogspot.com. Lot of great information. I am Tech guy. I have been a Desktop Technician since 1997 but have tons of other interests. In my spare time... Oh, wait I don't have any of that (just kidding). Anyways, I have been aware of this website for quite some time and decided to join the community and contribute as well as learn a lot from others. I am excited to get started on the forum and am looking forward to a great journey together. Lots of potential friends and I look forward to meeting many online.


Anonymous said...

best one for developing web development knowledge


Anonymous said...

sir i did the same thing what u have given but there s error n connectionstring can u help me out


Anonymous said...

after i am getting the values in the textbox which is in default2.aspx if iam trying to update i cant able to update the record kindly give code


Anonymous said...

how to update the Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim strID As String = Request.QueryString("id")
Dim strName As String = Request.QueryString("name")
Dim strLocation As String = Request.QueryString("loc")
lblID.Text = strID
lblName.Text = strName
lblLocation.Text = strLocation
End Sub

after this how to update the querystring ,in button click plz tell me the code


Anonymous said...

thank u very much


jooey said...

I was little bit of confusing whenever there is use of Hyperlink field but now thanks a lot to u to make me understood.


Magento themes said...

That is the Quiry string extension


MENAKA said...

how can i get an image also to another page which is in gridview?


MENAKA said...

HOW CAN I GET IMAGE TO ANOTHER PAGE WHICH IS IN GRIDVIEW BY CLICK ON THAT IMAGE?


Evangelin Balaiyan said...

Hi i used the above code for passing a row values of a grid from one page to another page. the text "Transfer values to other page" is not hyperlinked while am run my page. Help me for this task......


justicet said...

How do i the value that i get from the Hyperlink as a parameter in the same page?


Anonymous said...

tried to use this with linq to sql but got an error on the page with the gridview stating that System.WEB.UI.WebControls.DataControlField Collection is not allowed. Any thoughts?


Anonymous said...

This comment has been removed by a blog administrator.


Tariq hashmi said...

thanks a lot...................


Unknown said...

Thank Youuuu


Find More Articles