Hello Kerem,
Below you will find all the code behind containing the dropdown control with
the problem.
As additional information, there are two other dropdown controls that work
okay but their values were entered manually using the control properties.
Why the control populated with a datareader does not work?
I really appreciate your help.
Carlos
------------ Here is the code -------
Public Class ParmsRedirect
Inherits System.Web.UI.Page
Public sRedirectPage As String
Public sTitle As String
Public sType As String
Private sMonthYear As String
Private sSwitchboard As String
Private sRedirect As String
Public sCustomerId As String
Protected WithEvents MonthSel As System.Web.UI.WebControls.DropDownList
Protected WithEvents yearSel As System.Web.UI.WebControls.DropDownList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents lblTitle As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents sFileNum As System.Web.UI.WebControls.TextBox
Protected WithEvents Submit1 As System.Web.UI.WebControls.Button
Protected WithEvents cmdCancel As System.Web.UI.WebControls.Button
Protected WithEvents CmdCancel1 As System.Web.UI.WebControls.Button
Protected WithEvents CustomerSel As System.Web.UI.WebControls.DropDownList
Protected WithEvents Label5 As System.Web.UI.WebControls.Label
Protected WithEvents Submit As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
sRedirectPage = Request.QueryString("RedirectPage")
sTitle = Request.QueryString("Title")
sType = Request.QueryString("Type")
sSwitchboard = Request.QueryString("switchboard")
Me.lblTitle.Text = "<strong>" & sTitle & "</strong>"
Call fillCustomer() ' This populates the dropdown control
End Sub
Private Sub fillCustomer()
Dim sSQL As String
Dim cDb As New DBNet.cDBNet
Dim dr As SqlClient.SqlDataReader
sSQL = "select RTRIM(lastname) + ', ' + RTRIM(firstname) + ' ' + " & _
"CASE WHEN middlename is null THEN '' ELSE middlename END as
applicantname, file_num " & _
"from Applicant " & _
"where Not lastname Is null And Not firstname Is null and
lastname like 'a%'" & _
"order by lastname, firstname"
dr = cDb.getDataReader(sSQL)
If dr.HasRows Then
Me.CustomerSel.DataSource = dr
Me.CustomerSel.DataTextField = "ApplicantName"
Me.CustomerSel.DataValueField = "File_Num"
Me.CustomerSel.DataBind()
Me.CustomerSel.Items.Insert(0, "")
End If
cDb.closeConnection()
End Sub
Private Sub CustomerSel_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles CustomerSel.SelectedIndexChanged
' The event is fired and gets here, but sCustomerId always gets "".
' The selectedValue has "" (?????)
sCustomerId = Me.CustomerSel.SelectedValue
End Sub
Private Sub Submit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Submit.Click
' MothSel and yearSel are dropdown controls too with values entered
manually. They work okay.
sMonthYear = Me.MonthSel.SelectedValue & "/" &
Right(Me.yearSel.SelectedValue, 2)
' The value got from the dropdown event is used below, but never has a value.
Response.Redirect(Server.UrlDecode(sRedirectPage) & "&MonthYear=" &
sMonthYear & "&CustomerId=" & sCustomerId.ToString())
' The problem is related to the dropdown control that was populated with the
' dataReader. Any ideas? Than kyou.
End Sub
End Class
--------------- End of code ------------