ndraycott
New member
- Joined
- Nov 26, 2011
- Messages
- 2
- Programming Experience
- Beginner
Hi
I am trying to bind a list box with Video data from an sql query and use the selected url of the video in a session object posted to another page media player object. The problem is that i'm not sure why the session value is not being passed. And whether the binding is correct.
Thanks
I am trying to bind a list box with Video data from an sql query and use the selected url of the video in a session object posted to another page media player object. The problem is that i'm not sure why the session value is not being passed. And whether the binding is correct.
Thanks
VB.NET:
Protected Sub btnAdvancedSearch_Click(sender As Object, e As System.EventArgs) Handles btnAdvancedSearch.Click
If cboCourseSearch.SelectedIndex > 0 Then
lblErrorCourse.Text = ""
If cboModuleSearch.SelectedIndex > 0 Then
lblErrorModule.Text = ""
Dim ConnString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString()
'Create a connection to your sql server database
Dim connection As New SqlConnection(ConnString)
'Create a DataAdapter that will be used to issue a SELECT command
'to retrieve data from your table.
Dim adapter As New SqlDataAdapter("SELECT VideoName, VideoNo, VideoUrl FROM Video where CourseNo='" & cboCourseSearch.SelectedValue & "'and ModuleNo='" & cboModuleSearch.SelectedValue & "'", connection)
'Create a DataTable object to hold the data returned via the DataAdapter
Dim dt As New DataTable("VideoNameTable")
'Use the Fill method of the DataAdapter to populate the DataTable.
'the Fill method handles the opening and closing of the database connection
'connection.Open and connection.Close methods.
adapter.Fill(dt)
If (dt Is Nothing) Or (dt.Rows.Count = 0) Then
lblError.Text = "Sorry No Videos Meet That Search Criteria"
lstSearchAdvanced.Items.Clear()
Else
lblError.Text = ""
lstSearchAdvanced.DataSource = dt
'listbox data
lstSearchAdvanced.DataMember = "VideoUrl"
'lstSearchAdvanced.DataSource = "VideoUrl"
'bind the listbox
lstSearchAdvanced.DataBind()
End If
Else
lblErrorModule.Text = "Please Select a Module"
End If
Else
lblErrorCourse.Text = "Please Select a Course"
End If
End Sub
Protected Sub btnPlay_Click(sender As Object, e As System.EventArgs) Handles btnPlay.Click
If lstSearchAdvanced.SelectedIndex >= -1 Then
VideoSrc = lstSearchAdvanced.SelectedValue
Session("VideoFile") = VideoSrc
Response.Redirect("video_1.aspx")
Else
'if no selection made show an error message
lblError.Text = "You must select an item on the list to view it"
End If
End Sub
End Class