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