Wednesday, March 21, 2012

passing variables to new aspx page using hyperlink column from a datagrid

I am trying to get the value of the hyperlink column to the second aspx page to use it in a sql query. I have it passing to the new page. I don't know how to get/receive it in the new page. Any help would be appreciated.

<Columns>
<asp:TemplateColumn ><ItemTemplate>
<asp:HyperLink runat="Server" NavigateUrl='<%# "../IPDP/ViewObjective.aspx?PlanID=" & DataBinder.Eval(Container.DataItem, "IPDP_PLAN_ID") & "&ObjID=" & DataBinder.Eval(Container.DataItem, "IPDP_OBJ_ID")%>' Text="VIEW" ID="hyperObj"/>
</asp:HyperLink></ItemTemplate></asp:TemplateColumn

example on other page request("PlanID")
Maybe I'm misunderstanding you. This is what I have and the error it's giving me.

From page1:
<asp:TemplateColumn HeaderText="Select Ticket">
<ItemTemplate>
<asp:HyperLink id="HyperLink1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Number")%>' NavigateUrl='<%# "ticketsearch_db2a.aspx?Number=" & DataBinder.Eval(Container, "DataItem.Number")%>' />
</ItemTemplate>
</asp:TemplateColumn
On page2:

Dim TicNumber as string
TicNumber = request("Number")
Dim vNumber as String
Dim vName as String
Dim vDtissue as String
Dim vrace as String
Dim vsex as String
Dim vDlNum as String
Dim voffcode as String
Dim vspact as String
Dim vsppost as String
Dim vDtCourt as String
Dim vCity as String
Dim vStreet as String
Dim vCitype as String
Dim vCourt as String
Dim strConn as string = "server='sma18'; user id='sdasch'; password='ilovemynewhouse'; database='bluegrass"& _
"'"
Sub DoQuery(Source as Object, E as EventArgs)

Dim MySQL as string = "SELECT [Tickets].* FROM [Tickets] WHERE [Tickets].[number] = '" & TicNumber & "'"
Dim MyConn as New SQLConnection(strConn)
Dim ds as DataSet=New DataSet()
Dim Cmd as New SQLDataAdapter(MySQL,MyConn)
Cmd.Fill(ds,"Tickets")

'These lines assign the data to a variable, which is then assigned to the text property of a literal control(litEmps)
Dim dr As DataRow
For Each dr In ds.Tables("Tickets").Rows
vNumber+=dr("vnumber")
vName+=dr("first") & " " & dr("middle") & " " & dr("last") & " " & dr("suffix")
vDtissue+=dr("dtissue")
vrace+=dr("race")
vsex+=dr("sex")
vDlNum+=dr("dlnum")
voffcode+=dr("offcode")
vspact+=dr("spact")
vsppost+=dr("sppost")
vDtcourt+=dr("dtcourt")
vCity+=dr("city")
vStreet+=dr("street")
vCitype+=dr("citype")
vcourt+=dr("court")
Next
number1.text=vNumber
name1.text=vName
dtissue1.text=vdtissue
race1.text=vrace
sex1.text=vsex
DlNum1.text=vdlnum
offcode1.text=voffcode
spact1.text=vspact
sppost1.text=vsppost
Dtcourt1.text=vdtcourt
Street1.text=vstreet

Error:
Compiler Error Message: BC30188: Declaration expected.

Line 7: Dim TicNumber as string
Line 8: TicNumber = request("Number")
you can try Request.QueryString.Get("Number") for line 8
Thanks for trying. That gives me the same error.

I have <%=Request("Number")%> in the HTML portion of the code and that seems to give me the Number printed on the screen. I just need to figure out how to get it into a variable to use in the sql statement.

If you have any other ideas, I would appreciate them.

Again, Thanks for your help.

Follow this logic...

Function getRequestID()
Dim ID as INTEGER
ID = Request.QueryString("ID")
return ID
END FUNCTION

Where Function is called...
Page.aspx?ID=<%=getRequestID()%>

0 comments:

Post a Comment