Answered by:
How to use command argument with hyperlink

Question
-
User1717218719 posted
I have he following code which works perfectly for a linkbutton but now I want to use a hyperlink. Is it possinle to use command argument with hyperlink? If so how would I go about that?
Dim Lnkbtn As LinkButton = CType(sender, LinkButton) Dim CommandName As String = Lnkbtn.CommandName Dim CommandArgument As String = Lnkbtn.CommandArgument
Monday, May 20, 2019 8:47 AM
Answers
-
User665608656 posted
Hi E.RU,
According to your description , you need to re-modify your method code behind.
Here I'll provide a complete example of what I did.
In my example, I created a WebForm_0528_2155726.aspx page to store the GridView containing click links.
My GridView has four data fields which are RowNumber, FruitName,UnitPrice,Quantity and one Template Field which contains HyperLink control.
In addition to my key field RowNumber display and the Hyperlink control in Template display, I hidden other data fields by adding Visible= "false" .
Then passing the four data fields to the new page Popup.aspx in the NavigateUrl attribute of Template's HyperLink field.
Accept the passed parameters in the page_load event of the Popup.aspx page and assign them to the corresponding textbox.
Here is my complete code:
code in WebForm_0528_2155726.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm_0528_2155726.aspx.cs" Inherits="ForthProject.Cases.WebForm_0528_2155726" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div style="width: auto; height: auto"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="RowNumber"> <Columns> <asp:BoundField DataField="RowNumber" HeaderText="RowNumber" ReadOnly="True" SortExpression="RowNumber" /> <asp:BoundField DataField="FruitName" HeaderText="FruitName" ReadOnly="True" SortExpression="FruitName" Visible="false" /> <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" ReadOnly="True" SortExpression="UnitPrice" Visible="false" /> <asp:BoundField DataField="Quantity" HeaderText="Quantity" ReadOnly="True" SortExpression="Quantity" Visible="false" /> <asp:TemplateField HeaderText="Def"> <ItemTemplate> <asp:HyperLink ID="HL_Def" runat="server" Text='<%# Eval("RowNumber") %>' Style="color: red" NavigateUrl='<%# String.Format("Javascript:window.open(\"Popup.aspx?RowNumber={0}&FruitName={1}&UnitPrice={2}&Quantity={3}\",\"\",\"width=550,height=600,scrollbars=1,resizable=1\");", Eval("RowNumber"), Eval("FruitName"),Eval("UnitPrice"),Eval("Quantity")) %>' /> </ItemTemplate> <ItemStyle HorizontalAlign="Center" /> </asp:TemplateField> </Columns> </asp:GridView> </div> </form> </body> </html>
code behind in WebForm_0528_2155726.aspx:
Class SurroundingClass Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Not IsPostBack Then BindData1() End Sub Public Sub BindData1() Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString Dim strSql As String = "select * from Fruits" Using connection As SqlConnection = New SqlConnection(connectionString) Using cmd As SqlCommand = New SqlCommand(strSql, connection) Try connection.Open() Dim da As SqlDataAdapter = New SqlDataAdapter(cmd) Dim ds As DataSet = New DataSet() da.Fill(ds) GridView1.DataSource = ds.Tables(0) GridView1.DataBind() Catch ex As SqlException Throw New Exception(ex.Message) Finally connection.Close() End Try End Using End Using End Sub End Class
code in Popup.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Popup.aspx.cs" Inherits="ForthProject.Cases.Popup" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> RowNumber: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> FruitName: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /> UnitPrice: <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <br /> Quantity: <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> </div> </form> </body> </html>
code behind in Popup.aspx:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim rowNumber As String = Request.QueryString("RowNumber") Dim FruitName As String = Request.QueryString("FruitName") Dim unitPrice As String = Request.QueryString("UnitPrice") Dim quantity As String = Request.QueryString("Quantity") TextBox1.Text = rowNumber TextBox2.Text = FruitName TextBox3.Text = unitPrice TextBox4.Text = quantity End Sub
The result of my work demo:
Best Regards,
YongQing.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, May 29, 2019 9:40 AM
All replies
-
User753101303 posted
Hi,
No, an hyperlink is just the counterpart of a "a" tag and doesn't have the CommandName or the CommandArgument (which is for "buttons").Edit: see https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.ibuttoncontrol?view=netframework-4.8
Depends what is your current use case. If you are only showing data, you may not need the command name and the argument could be a query string value (the purpose of a link is to direct the user somewhere to show data).
If doing really an action that ends up in changing data it coould be best to keep a LinkButton.
Monday, May 20, 2019 9:13 AM -
User1717218719 posted
Hi Patrice,
Thank you for your reply.
Dim LnkBtnAs LinkButton = CType(sender, LinkButton ) Dim CommandName As String = LnkBtn.CommandName Dim CommandArgument As String = LnkBtn.CommandArgument.tostring strOleCon = "Data Source=xxxxx;Initial Catalog=dbtesting;Trusted_Connection=True;" conConn = New SqlConnection(strOleCon) Dim testrow As GridViewRow = GridView1.Rows(LnkBtn.CommandArgument) Dim strTblNbrLst As String = Nothing For i As Integer = 0 To 7 strTblNbrLst &= "," & testrow.Cells(10 + i).Text Next strTblNbrLst = strTblNbrLst.TrimStart(",") comComm = New SqlCommand With comComm .Connection = conConn .CommandType = CommandType.Text .CommandText = "SELECT * FROM tbl WHERE Tblnb IN ('" & strTblNbrLst.Replace(",", "','") & "') " End With adpAdap = New SqlDataAdapter(comComm) adpAdap.Fill(Datatbl)
this is the code im looking to use but with a hyperlink instead of a button.Monday, May 20, 2019 9:30 AM -
User753101303 posted
Hi,
Seems the CommandName is not used at all. Some code is missing to fully understand what you are doing but it seems you could use an hyperlinkfield:
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.hyperlinkfield?view=netframework-4.8For now it seems that when clicking a link on a gridview row you want to see child rows in another gridview maybe ? (and so the 2nd gridview would act based on which value is passed as query string).
Monday, May 20, 2019 9:46 AM -
User1717218719 posted
Yes the commandname is not used I will take that out thanks for that. Here is my full code. I am trying to display the text belong to ID's in another table. I have displayed the numbers in the gridview and now when the hyper link is clicked I want the text data to be displayed. Basically I am looking to read every row in gridview with hyperlink asp.net vb
Monday, May 20, 2019 9:59 AM -
User665608656 posted
Hi E.RU,
According to the code you provided based on clicking LinkButton, if you want to achieve the function through hyperlink, I recommend that you use the NavigateUrl attribute of hyperlinkfield to pass different parameters, and use QueryString to get parameters to display the detailed data of each line.
For more detailed code, please refer to the following code:
<div style="width: auto; height: auto"> <div style="width: 10%; height: 100%; float: left"> ID:<br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="RowNumber"> <Columns> <asp:BoundField DataField="RowNumber" HeaderText="RowNumber" ReadOnly="True" SortExpression="RowNumber" /> <asp:TemplateField HeaderText="Link"> <ItemTemplate> <asp:HyperLink ID="declare_id" runat="server" Text='Details' NavigateUrl=' <%# "WebForm_0521_2155726.aspx?RowNumber=" + Eval("RowNumber") %>'> </asp:HyperLink> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div> <div style=" height: 100%;" > Text:<br /> <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="RowNumber"> <Columns> <asp:BoundField DataField="RowNumber" HeaderText="RowNumber" ReadOnly="True" SortExpression="RowNumber" Visible="false" /> <asp:BoundField DataField="FruitName" HeaderText="FruitName" SortExpression="FruitName" /> <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" /> <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" /> </Columns> </asp:GridView> </div> </div>
code behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Not IsPostBack Then BindData1() End If Dim rowNumber As String = Request.QueryString("RowNumber") If Not String.IsNullOrEmpty(rowNumber) Then BindDataDetails(rowNumber) End If End Sub
The result of my work demo:
Best Regards,YongQing.
Tuesday, May 21, 2019 5:41 AM -
User1717218719 posted
Thabk you this is very helpful. by BindData1() what do you mean. do I have to re do my sql connection string and bind into gridview all over again? if possible I would just like to display in textbox without gridview.
This is what I have so far thaks to your code.
when I use my code nothing goes into the textbox but I dont recieve any errors
<asp:TemplateField HeaderText="Def"> <ItemTemplate> <asp:HyperLink ID="HL" runat="server" Text='<%# Eval("x") %>' Style="color: red" NavigateUrl='<%# "javascript: windowOpener(""taxPopup.aspx?TblNbr=" & Eval("Def") & """,""mypop"",""width=550,height=600,scrollbars=1,resizable=1"");" %>' /> </ItemTemplate> <ItemStyle HorizontalAlign="Center" /> </asp:TemplateField>
Private Sub taxPopup_Load(sender As Object, e As EventArgs) Handles Me.Load Me.Label12.Text = Nothing Me.Label12.Text = Request.QueryString("TblNo") Me.TextBox1.Text = Nothing Dim str As String = Request.QueryString("x") Me.TextBox1.Text = str If Me.Page.PreviousPage IsNot Nothing Then Dim TblNbr As Integer = Integer.Parse(Request.QueryString("x")) Dim GridView1 As GridView = DirectCast(Me.Page.PreviousPage.FindControl("GridView1"), GridView) Dim row As GridViewRow = GridView1.Rows(TblNo) TextBox1.Text = CType(row.FindControl("x"), TextBox).Text End If End Sub
Tuesday, May 21, 2019 8:55 AM -
User665608656 posted
Hi E.RU,
BindData1() in my code is a data binding method for GridView1.
You don't have to repeat SQL to get data. You could add multiple parameters after querystring to pass the fields you want when you click on a data.
The reason why textbox doesn't display data after you click the hyperlink is that you use windowsopener, which is a readable and writable property that returns a reference to the windows object that created the window.
Since [windowsopener]( https://developer.mozilla.org/en-US/docs/Web/API/Window/opener) is just a property not a function to open the new window, you will find the value doesn’t go to textbox. I suggest you could use window.open (), or use URL directly without writing the JS method.
For more detailed code, please refer to the following code:
<form id="form1" runat="server"> <div style="width: auto; height: auto"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="RowNumber"> <Columns> <asp:BoundField DataField="RowNumber" HeaderText="RowNumber" ReadOnly="True" SortExpression="RowNumber" /> <asp:BoundField DataField="FruitName" HeaderText="FruitName" ReadOnly="True" SortExpression="FruitName" Visible="false"/> <asp:TemplateField HeaderText="Def"> <ItemTemplate> <asp:HyperLink ID="HL_Def" runat="server" Text='<%# Eval("RowNumber") %>' Style="color: red" NavigateUrl='<%# String.Format("Javascript:window.open(\"WebForm_0521_2155726.aspx?RowNumber={0}&FruitName={1}\",\"_self\",\"\");", Eval("RowNumber"), Eval("FruitName")) %>' /> <%-- or you can use it like below--%> <%--<asp:HyperLink ID="declare_id" runat="server" Text='Details' NavigateUrl=' <%# "WebForm_0521_2155726.aspx?RowNumber=" + Eval("RowNumber") +"FruitName=" + Eval("FruitName") %>'> </asp:HyperLink>--%> </ItemTemplate> <ItemStyle HorizontalAlign="Center" /> </asp:TemplateField> </Columns> </asp:GridView> <br /> <br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </div> </form>
code behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Not IsPostBack Then BindData1() End If Dim rowNumber As String = Request.QueryString("RowNumber") Dim FruitName As String = Request.QueryString("FruitName") If Not String.IsNullOrEmpty(rowNumber) Then Label1.Text = rowNumber TextBox1.Text = FruitName End If End Sub Public Sub BindData1() Dim connectionString As String = ConfigurationManager.ConnectionStrings("TestConnectionString1").ConnectionString Dim strSql As String = "select * from Fruits" Using connection As SqlConnection = New SqlConnection(connectionString) Using cmd As SqlCommand = New SqlCommand(strSql, connection) Try connection.Open() Dim da As SqlDataAdapter = New SqlDataAdapter(cmd) Dim ds As DataSet = New DataSet() da.Fill(ds) GridView1.DataSource = ds.Tables(0) GridView1.DataBind() Catch ex As SqlException Throw New Exception(ex.Message) Finally connection.Close() End Try End Using End Using End Sub
The result of my work demo:
Best Regards,YongQing.
Wednesday, May 22, 2019 3:12 AM -
User1717218719 posted
I have tried this code but seem to get nothing the pop up just keeps trying to load then times out.
Private Sub taxPopup_Load(sender As Object, e As EventArgs) Handles Me.Load Me.Label12.Text = Nothing Me.Label12.Text = Request.QueryString("TblNo") Me.TextBox1.Text = Nothing Me.TextBox1.Text = "test" If Not IsPostBack Then BindData1() End If Dim TblNbr As String = Request.QueryString("TblNo") Dim y As String = Request.QueryString("x") If Not String.IsNullOrEmpty(TblNo) Then TextBox1.Text = y End If End Sub Dim conConn As SqlConnection = Nothing Dim strSQLCon As String = Nothing Dim comComm As SqlCommand = Nothing Dim adpAdap As SqlDataAdapter = Nothing Dim DataS As New DataSet Dim Datatbl As New DataTable Public Sub BindData1() strSQLCon = "Data Source=xxxxxxxxxxx;" conConn = New SqlConnection(strSQLCon) Try conConn.Open() comComm = New SqlCommand With comComm .Connection = conConn .CommandText = "SELECT * FROM tbl" End With '-- Fill a datable with the above adpAdap = New SqlDataAdapter(comComm) adpAdap.Fill(Datatbl) Dim ds As DataSet = New DataSet() GridView1.DataSource = ds.Tables(0) GridView1.DataBind() Catch ex As SqlException Throw New Exception(ex.Message) Finally conConn.Close() End Try End Sub
Wednesday, May 22, 2019 9:18 AM -
User665608656 posted
Hi E.RU,
I tested it with the code you provided, and found that there was no problem.
Could you please provide your detailed front desk code?
If you could post more details information, it will be more easily for us to reproduce the issue and find out the solution.
Best Regards,YongQing.
Wednesday, May 22, 2019 10:27 AM -
User1717218719 posted
<asp:TemplateField HeaderText="Def"> <ItemTemplate> <asp:HyperLink ID="HL_Def" runat="server" Text='<%# Eval("x") %>' Style="color: red" NavigateUrl='<%# "javascript: windowOpener(""Popup.aspx?TblNbr=" & Eval("TaxDef") & """,""mypop"",""width=550,height=600,scrollbars=1,resizable=1"");" %>' /> </ItemTemplate> <ItemStyle HorizontalAlign="Center" /> </asp:TemplateField>
I tried changed windowopner to window.open also with no luck. thanks for investing time into this.
Wednesday, May 22, 2019 11:08 AM -
User665608656 posted
Hi E.RU,
According to your codes,the front-end code you provided is still using windowopener.
The window.open() method you use is similar to the code I provided below? I hope you could provide the code when you use the window.open() method.
<asp:HyperLink ID="HL_Def" runat="server" Text='<%# Eval("Def") %>' Style="color: red" NavigateUrl='<%# String.Format("Javascript:window.open(\"Popup.aspx?tblnbr={0}\",\"_self\",\"\");", Eval("Ins")) %>' />
Best Regards,
YongQing.
Thursday, May 23, 2019 12:34 AM -
User1717218719 posted
when I run the code with window.open I get the error "Object doesn't support property or method 'Open'"
Also when I run your hyperlink word for word I am getting some sort of error saying "
comma, ')',or a valid expression continuation expected"
when I run this code I get the error "Unable to complete Hyperlink event.Object reference not set to an instance of an object." on the line
Dim GridView1 As GridView = CType(Page.PreviousPage.FindControl("GridView1"), GridView)
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load Me.Label12.Text = Nothing Me.Label12.Text = Request.QueryString("TblNbr") Try strSQLCon = "Data Source=xxxxxxxxxxxxx;" conConn = New SqlConnection(strSQLCon) ' Dim tblnbr As Integer = Integer.Parse(Request.QueryString("tblnbr")) ''''' Dim GridView1 As GridView = DirectCast(Me.Page.PreviousPage.FindControl("GridView1"), GridView) Dim GridView1 As GridView = CType(Page.PreviousPage.FindControl("GridView1"), GridView) Dim testrow As GridViewRow = GridView1.Rows("x") Dim strTblNbrLst As String = Nothing For i As Integer = 0 To 7 strTblNbrLst &= "," & testrow.Cells(10 + i).Text Next strTblNbrLst = strTblNbrLst.TrimStart(",") comComm = New SqlCommand With comComm .Connection = conConn .CommandType = CommandType.Text .CommandText = "SELECT * FROM tbl WHERE TblNbr IN ('" & strTblNbrLst.Replace(",", "','") & "') ORDER BY TblNbr, LneNbr" End With '-- Fill a datable with the above adpAdap = New SqlDataAdapter(comComm) adpAdap.Fill(Datatbl) Dim dv As New DataView(Datatbl) Dim arrTblNbrLst() As String = Strings.Split(strTblNbrLst, ",") For i As Integer = 0 To arrTblNbrLst.Count - 1 dv.RowFilter = "TblNbr = '" & arrTblNbrLst(i) & "'" Dim strTemp As String = Nothing For k As Integer = 0 To dv.Count - 1 strTemp &= dv(k)("TxtDat").ToString Next Me.TextBoxPop.Text = strTemp Next Catch ex As Exception MsgBox("Error: Unable to complete HyperLink Event. " & ex.Message & ex.StackTrace) Finally If Not IsNothing(conConn) Then conConn.Close() End Try End Sub End Class
Tuesday, May 28, 2019 8:55 AM -
User665608656 posted
Hi E.RU,
According to your code behind, do you want to open a new page by clicking hyperlink, and show the other fields corresponding to the row of hyperlink you clicked on the new page is displayed?
If so, I suggest you could not better to get the GridView on the previous page,but pass multiple parameters to the new page in NavigateUrl of hyperlink.
You could refer to this link: https://www.aspsnippets.com/Articles/How-to-bind-and-pass-query-string-in-HyperLink-in-GridView-in-ASPNet.aspx
Best Regards,
YongQing.
Wednesday, May 29, 2019 1:21 AM -
User1717218719 posted
yes thats exactly what I want I have tried this example with no luck.
Wednesday, May 29, 2019 8:04 AM -
User665608656 posted
Hi E.RU,
According to your description , you need to re-modify your method code behind.
Here I'll provide a complete example of what I did.
In my example, I created a WebForm_0528_2155726.aspx page to store the GridView containing click links.
My GridView has four data fields which are RowNumber, FruitName,UnitPrice,Quantity and one Template Field which contains HyperLink control.
In addition to my key field RowNumber display and the Hyperlink control in Template display, I hidden other data fields by adding Visible= "false" .
Then passing the four data fields to the new page Popup.aspx in the NavigateUrl attribute of Template's HyperLink field.
Accept the passed parameters in the page_load event of the Popup.aspx page and assign them to the corresponding textbox.
Here is my complete code:
code in WebForm_0528_2155726.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm_0528_2155726.aspx.cs" Inherits="ForthProject.Cases.WebForm_0528_2155726" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div style="width: auto; height: auto"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="RowNumber"> <Columns> <asp:BoundField DataField="RowNumber" HeaderText="RowNumber" ReadOnly="True" SortExpression="RowNumber" /> <asp:BoundField DataField="FruitName" HeaderText="FruitName" ReadOnly="True" SortExpression="FruitName" Visible="false" /> <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" ReadOnly="True" SortExpression="UnitPrice" Visible="false" /> <asp:BoundField DataField="Quantity" HeaderText="Quantity" ReadOnly="True" SortExpression="Quantity" Visible="false" /> <asp:TemplateField HeaderText="Def"> <ItemTemplate> <asp:HyperLink ID="HL_Def" runat="server" Text='<%# Eval("RowNumber") %>' Style="color: red" NavigateUrl='<%# String.Format("Javascript:window.open(\"Popup.aspx?RowNumber={0}&FruitName={1}&UnitPrice={2}&Quantity={3}\",\"\",\"width=550,height=600,scrollbars=1,resizable=1\");", Eval("RowNumber"), Eval("FruitName"),Eval("UnitPrice"),Eval("Quantity")) %>' /> </ItemTemplate> <ItemStyle HorizontalAlign="Center" /> </asp:TemplateField> </Columns> </asp:GridView> </div> </form> </body> </html>
code behind in WebForm_0528_2155726.aspx:
Class SurroundingClass Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Not IsPostBack Then BindData1() End Sub Public Sub BindData1() Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString Dim strSql As String = "select * from Fruits" Using connection As SqlConnection = New SqlConnection(connectionString) Using cmd As SqlCommand = New SqlCommand(strSql, connection) Try connection.Open() Dim da As SqlDataAdapter = New SqlDataAdapter(cmd) Dim ds As DataSet = New DataSet() da.Fill(ds) GridView1.DataSource = ds.Tables(0) GridView1.DataBind() Catch ex As SqlException Throw New Exception(ex.Message) Finally connection.Close() End Try End Using End Using End Sub End Class
code in Popup.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Popup.aspx.cs" Inherits="ForthProject.Cases.Popup" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> RowNumber: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> FruitName: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /> UnitPrice: <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <br /> Quantity: <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> </div> </form> </body> </html>
code behind in Popup.aspx:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim rowNumber As String = Request.QueryString("RowNumber") Dim FruitName As String = Request.QueryString("FruitName") Dim unitPrice As String = Request.QueryString("UnitPrice") Dim quantity As String = Request.QueryString("Quantity") TextBox1.Text = rowNumber TextBox2.Text = FruitName TextBox3.Text = unitPrice TextBox4.Text = quantity End Sub
The result of my work demo:
Best Regards,
YongQing.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, May 29, 2019 9:40 AM -
User1717218719 posted
thankyou so much this Is very helpful. this Is almost what I want. so I have two sql tables one tblx2(contains numbers) And one tbl64(contains text). tblx2 Is what Is displayed In the gridview. When I click the link In gridview I want To display the text data In the New page In textbox.
This is the code I have which displays all the text for every column in the textbox on my popup page. I only want the relevant text to display ie.then text relating to the link I click. How do I go about this?
Wednesday, May 29, 2019 10:10 AM -
User665608656 posted
Hi E.RU,
According to your description, do you mean that Tbx2 and tbl64 are two tables related?
Do you want to display the text in tbl64 on the popup page?
If so, you could get the number passed in from the popup page, then take the number value as a parameter, and use ado.net to query the text you want to display in the tbl64 table and put it in the textbox.
Best Regards,
YongQing.
Thursday, May 30, 2019 1:15 AM -
User1717218719 posted
yes the tables are related. How would I go about coding that I am not familiar with ado.net.
Many Thanks
Thursday, May 30, 2019 8:01 AM -
User665608656 posted
Hi E.RU,
Here is a sql example in popup.aspx for you to get the text from tbl64 according to the number passed by gridview:
Dim number As String = Request.QueryString("TblNbr") Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString Dim strSql As String = "select text from tbl64 where tbl64.numbers = " & number Using connection As SqlConnection = New SqlConnection(connectionString) Using cmd As SqlCommand = New SqlCommand(strSql, connection) Try connection.Open() Dim da As SqlDataAdapter = New SqlDataAdapter(cmd) Dim ds As DataSet = New DataSet() da.Fill(ds)
Me.TextBoxPop.Text = ds.Tables(0).Rows(0)(0).ToString() Catch ex As SqlException Throw New Exception(ex.Message) Finally connection.Close() End Try End Using End UsingBest Regards,
YongQing.
Thursday, May 30, 2019 9:56 AM -
User1717218719 posted
thanks so much for your reply however the only issue with this code Is that I dont want to have to input the number each time as i have many numbers And links. Is it possible to code it so the code identifies the number on the link clicked? also i have multiple numbers which are the same (but different links on different lines) and dont want the text repleated. someting like select * from table where hyperlink has been clicked if that even exists
Thursday, May 30, 2019 10:04 AM -
User1717218719 posted
Hi All
I am still trying to work this out I have he textbox displaying some data but not the specific data I want. The code I have reads through the all the rows and columns not just the one that is clicked. I have used a query string which displayed the correct tbl no. I now want the text behind that number is is possible to do something like
While Request.QueryString("TblNbr") = the clicked hyperlink
textboxpop.text = TxtDat (OF THE LINK CLICKED)
End While
Thursday, June 6, 2019 10:45 AM