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

please, can you post the whole source code in vb.net with the asp.net pages
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteIN 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)
ReplyDeletePrivate 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
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
ReplyDeleteany reply or help appreciated
thanks a lot
thanks you
ReplyDeleteThanks it works for me.....
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteI 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.
ReplyDeletebest one for developing web development knowledge
ReplyDeletesir i did the same thing what u have given but there s error n connectionstring can u help me out
ReplyDeleteafter 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
ReplyDeletehow to update the Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
ReplyDeleteDim 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
thank u very much
ReplyDeleteI was little bit of confusing whenever there is use of Hyperlink field but now thanks a lot to u to make me understood.
ReplyDeleteThat is the Quiry string extension
ReplyDeletehow can i get an image also to another page which is in gridview?
ReplyDeleteHOW CAN I GET IMAGE TO ANOTHER PAGE WHICH IS IN GRIDVIEW BY CLICK ON THAT IMAGE?
ReplyDeleteHi 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......
ReplyDeleteHow do i the value that i get from the Hyperlink as a parameter in the same page?
ReplyDeletetried 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?
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeletethanks a lot...................
ReplyDeleteThank Youuuu
ReplyDelete