473,597 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populate a dropdown list with a variable from a Querystring

Hi,

I'm passing a variable to another page through a querystring. I then want
to use that variable to retrieve records from a database to poulate a
dropdownlist. I can read the variable from the querystring but I'm not sure
how to pass that value. I get the error that IntCourseID is not declared in:

<asp:DropDownLi st id="fLessonID" runat="server" DataValueField= "LessonID"
DataSource="<%# GetLessons(IntC ourseID) %>"

I tried moving the querystring outside the page load but that didn't work:

This is the code I have:

<%@ Page Language="VB" Debug="true" validaterequest ="false" %>

<script runat="server">

Sub Page_Load(sende r As Object, e As EventArgs)
If Page.IsPostBack = False Then
Dim IntCourseID as Integer
IntCourseID = Request.QuerySt ring( "CourseID" )

End If
End Sub
Function GetLessons(ByVa l courseID As Integer) As
System.Data.IDa taReader
Dim connectionStrin g As String = "server='(local )';
trusted_connect ion=true; database='xx'"
Dim dbConnection As System.Data.IDb Connection = New
System.Data.Sql Client.SqlConne ction(connectio nString)

Dim queryString As String = "SELECT [tblLesson].[LessonID],
[tblLesson].[LessonTitle] FROM [tblLesson] WHERE ("& _
"[tblLesson].[CourseID] = @CourseID)"
Dim dbCommand As System.Data.IDb Command = New
System.Data.Sql Client.SqlComma nd
dbCommand.Comma ndText = queryString
dbCommand.Conne ction = dbConnection

Dim dbParam_courseI D As System.Data.IDa taParameter = New
System.Data.Sql Client.SqlParam eter
dbParam_courseI D.ParameterName = "@CourseID"
dbParam_courseI D.Value = courseID
dbParam_courseI D.DbType = System.Data.DbT ype.Int32
dbCommand.Param eters.Add(dbPar am_courseID)

dbConnection.Op en
Dim dataReader As System.Data.IDa taReader =
dbCommand.Execu teReader(System .Data.CommandBe havior.CloseCon nection)

Return dataReader
End Function

Sub addButton_Click (sender As Object, e As EventArgs)
Response.Redire ct("selectPage. aspx")
End Sub

</script>
<html>
<head>
</head>
<body leftmargin="0" topmargin="0">
<form runat="server">
<asp:DropDownLi st id="fLessonID" runat="server"
DataValueField= "LessonID" DataSource="<%# GetLessons(IntC ourseID) %>"
DataTextField=" LessonTitle"></asp:DropDownLis t>
<asp:Button id="addButton" onclick="addBut ton_Click" runat="server"
Text="Next"></asp:Button>

</form>
</body>
</html>

Thanks for any help

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #1
2 4014
Hi Jim,

I understood your probleim in the following way after reading your code...

You have a Integer Variable (IntCourseID) in your code behind fi.e...and you
want to use that value in your .aspx page. Am I right...?

If I'm right....then solution for your problem is...

Have a hidden control...and assign your querystring value (CourseId) to the
value of the hidden control. Now you can use that control in your .aspx page
code, to bind with the ddl.

Cheers,

Jerome. M

"Jim via DotNetMonster.c om" wrote:
Hi,

I'm passing a variable to another page through a querystring. I then want
to use that variable to retrieve records from a database to poulate a
dropdownlist. I can read the variable from the querystring but I'm not sure
how to pass that value. I get the error that IntCourseID is not declared in:

<asp:DropDownLi st id="fLessonID" runat="server" DataValueField= "LessonID"
DataSource="<%# GetLessons(IntC ourseID) %>"

I tried moving the querystring outside the page load but that didn't work:

This is the code I have:

<%@ Page Language="VB" Debug="true" validaterequest ="false" %>

<script runat="server">

Sub Page_Load(sende r As Object, e As EventArgs)
If Page.IsPostBack = False Then
Dim IntCourseID as Integer
IntCourseID = Request.QuerySt ring( "CourseID" )

End If
End Sub
Function GetLessons(ByVa l courseID As Integer) As
System.Data.IDa taReader
Dim connectionStrin g As String = "server='(local )';
trusted_connect ion=true; database='xx'"
Dim dbConnection As System.Data.IDb Connection = New
System.Data.Sql Client.SqlConne ction(connectio nString)

Dim queryString As String = "SELECT [tblLesson].[LessonID],
[tblLesson].[LessonTitle] FROM [tblLesson] WHERE ("& _
"[tblLesson].[CourseID] = @CourseID)"
Dim dbCommand As System.Data.IDb Command = New
System.Data.Sql Client.SqlComma nd
dbCommand.Comma ndText = queryString
dbCommand.Conne ction = dbConnection

Dim dbParam_courseI D As System.Data.IDa taParameter = New
System.Data.Sql Client.SqlParam eter
dbParam_courseI D.ParameterName = "@CourseID"
dbParam_courseI D.Value = courseID
dbParam_courseI D.DbType = System.Data.DbT ype.Int32
dbCommand.Param eters.Add(dbPar am_courseID)

dbConnection.Op en
Dim dataReader As System.Data.IDa taReader =
dbCommand.Execu teReader(System .Data.CommandBe havior.CloseCon nection)

Return dataReader
End Function

Sub addButton_Click (sender As Object, e As EventArgs)
Response.Redire ct("selectPage. aspx")
End Sub

</script>
<html>
<head>
</head>
<body leftmargin="0" topmargin="0">
<form runat="server">
<asp:DropDownLi st id="fLessonID" runat="server"
DataValueField= "LessonID" DataSource="<%# GetLessons(IntC ourseID) %>"
DataTextField=" LessonTitle"></asp:DropDownLis t>
<asp:Button id="addButton" onclick="addBut ton_Click" runat="server"
Text="Next"></asp:Button>

</form>
</body>
</html>

Thanks for any help

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #2
Hello
Dear Jim!
First the problem with your code is that you are declaring a Variable in
pageload event "IntCourseI D" that will be destroyed when this event will
reach its end.
First Declare this variable in the GetLessons function
IntCourseID = Request.QuerySt ring( "CourseID" )
so that this variable with its value can be accessed.

Regards
Malik Asif
ASP.NET,VB.NET
"Jim via DotNetMonster.c om" <fo***@DotNetMo nster.com> wrote in message
news:85******** *************** *******@DotNetM onster.com...
Hi,

I'm passing a variable to another page through a querystring. I then want
to use that variable to retrieve records from a database to poulate a
dropdownlist. I can read the variable from the querystring but I'm not sure how to pass that value. I get the error that IntCourseID is not declared in:
<asp:DropDownLi st id="fLessonID" runat="server" DataValueField= "LessonID"
DataSource="<%# GetLessons(IntC ourseID) %>"

I tried moving the querystring outside the page load but that didn't work:

This is the code I have:

<%@ Page Language="VB" Debug="true" validaterequest ="false" %>

<script runat="server">

Sub Page_Load(sende r As Object, e As EventArgs)
If Page.IsPostBack = False Then
Dim IntCourseID as Integer
IntCourseID = Request.QuerySt ring( "CourseID" )

End If
End Sub
Function GetLessons(ByVa l courseID As Integer) As
System.Data.IDa taReader
Dim connectionStrin g As String = "server='(local )';
trusted_connect ion=true; database='xx'"
Dim dbConnection As System.Data.IDb Connection = New
System.Data.Sql Client.SqlConne ction(connectio nString)

Dim queryString As String = "SELECT [tblLesson].[LessonID],
[tblLesson].[LessonTitle] FROM [tblLesson] WHERE ("& _
"[tblLesson].[CourseID] = @CourseID)"
Dim dbCommand As System.Data.IDb Command = New
System.Data.Sql Client.SqlComma nd
dbCommand.Comma ndText = queryString
dbCommand.Conne ction = dbConnection

Dim dbParam_courseI D As System.Data.IDa taParameter = New
System.Data.Sql Client.SqlParam eter
dbParam_courseI D.ParameterName = "@CourseID"
dbParam_courseI D.Value = courseID
dbParam_courseI D.DbType = System.Data.DbT ype.Int32
dbCommand.Param eters.Add(dbPar am_courseID)

dbConnection.Op en
Dim dataReader As System.Data.IDa taReader =
dbCommand.Execu teReader(System .Data.CommandBe havior.CloseCon nection)

Return dataReader
End Function

Sub addButton_Click (sender As Object, e As EventArgs)
Response.Redire ct("selectPage. aspx")
End Sub

</script>
<html>
<head>
</head>
<body leftmargin="0" topmargin="0">
<form runat="server">
<asp:DropDownLi st id="fLessonID" runat="server"
DataValueField= "LessonID" DataSource="<%# GetLessons(IntC ourseID) %>"
DataTextField=" LessonTitle"></asp:DropDownLis t>
<asp:Button id="addButton" onclick="addBut ton_Click" runat="server" Text="Next"></asp:Button>

</form>
</body>
</html>

Thanks for any help

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
10215
by: Lisa | last post by:
I have a drop down that defaults to "select" after the page refreshes. How do I keep the selected value in the dropdown field... I've tried EVERYTHING and nothing works! :( <script LANGUAGE="JavaScript"> function getServer(form){ var cdoServerName = document.frmSoftware.cdoServerName.options.value;
20
12381
by: Dannyboyo | last post by:
I have what I hope is a simple request. I can't really code in javascript, but I am pretty good at cusomizing it with slight modifications. I code in ASP and HTML. I am trying to capture customer input of product names to put on custom labels we make. Some of the labels will have our product names on them, but the customer can add other products that we do not sell. So, on my product detail page I want a textbox that can have rows copied...
1
2478
by: news | last post by:
Hello, I need help with the following problem: An HTML page that have two dropdown list whit different values: 1. Dropdown list 1(tblname1) =values with different location's. After user has selected one value from the dropdown it should show values from
2
3023
by: jeffmagill | last post by:
Hello everyone, I have what I thought was a simple script but I cant figure it out. Anyway, I want to set the selected item of a drop down list with information i am recieving from request.querystring. Seems like this is a case of when learning asp.net first is a hindrance to what i want to do. Im looking for something to the effect of, Request.Form("dd_eventdate")= Request.QueryString("event")
5
11884
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My dropdown list control does not retain its SelectedValue. Unless I read the SelectedValue right after the control has been loaded, populated, and assigned with its original value (and of course that is
0
1605
by: Kay O'Keeffe | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp textbox control which has a 'TextMode' property and when clicked on, displays as a dropdown list with 3 values, I want to have a similar type property with a dropdown style.
11
7377
by: eureka | last post by:
Hi All, I'm training in Servlets, JSP and JavaScript, I have a web page in which there's a "StudentName" textbox and below it is a "Names" Dropdown list. Initially the Textbox is empty and the Dropdown doesnt have any items.. The requirement is that as soon as one goes on typing the letters in the StudentName-textbox the corresponding matching names have to appear
6
5843
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList ID="FldType_add" Runat="server" DataSource='< %#GetFieldType()%>' DataValueField="Type" DataTextField="Type" /> Oce the page is loaded all the values are added to the dropdown list. But when I thought of getting the selected value from the...
1
1858
by: fran7 | last post by:
Hi, Anyone know how to populate a dropdown list with data from database. I have an interface that generates the following code for names in my database. ..asp <%If Trim(rsCard("Author"))<>"" Then%> <%=rsCard("Author")%><%End If%> .. How does one populate a dropdown list??
0
7886
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5431
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3886
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3927
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2404
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1494
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.