Constructing ASP in VS2005. One dropdownlist control will notcooperate

B

Brent White

I can't figure out what I'm doing differently with this one drop-down
list control from the other two that are working just fine.

Background:

I am constructing a page that will allow a user to select style,
color, size from dropdown boxes and get a short datagrid report based
on that selection. When they select the style and hit a button, the
color (and eventually size) dropdown lists will automatically fill
based on the style selection, using a datareader class through an ADO
connection. The color and size lists work fine. You select a color
and size from the list and hit another command button and the datagrid
shows the data from a stored procedure on SQL Server 2005.

Initially, I had the style field set up as a text field for usability
testing, but I didn't want to raise the risk of a SQL Injection
attack, so I made it a dropdownlist instead by deleting the text box
and putting in a dropdown list with the same name. No problem, right?

Well, not exactly. It has a default value in it of 1250 (which would
be the first style avaialble to select, so that's right). The problem
is, regardless of the Autopostback value for the list, if you click on
another style, the dropdown list reverts back to 1250. Neither of the
other dropdown lists did this, but now I can't even click on the Load
Colors (button2) and get either of the dropdown lists to refresh.

Here's the VB code:

Partial Public Class _Default
Inherits System.Web.UI.Page


Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim cn As New System.Data.SqlClient.SqlConnection
Dim cmd As New System.Data.SqlClient.SqlCommand
cn.ConnectionString = "Password=;Persist Security
Info=True;User ID=sa;Initial Catalog=BadgerBlue;Data
Source=195.1.2.222"
cn.Open()
cmd.Connection = cn
cmd.CommandType = ADODB.CommandTypeEnum.adCmdText
cmd.CommandText = "SELECT DISTINCT STYLE FROM BBHOLD"
Dim rdr As System.Data.SqlClient.SqlDataReader =
cmd.ExecuteReader()
Me.STYLE.DataSource = rdr
Me.STYLE.DataTextField = "STYLE"
Me.STYLE.DataValueField = "STYLE"
Me.STYLE.DataBind()
cn.Close()
End Sub


Private Sub DropDownList1_TextChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.TextChanged
'Response.Write((DropDownList1.SelectedValue))
Dim cn As New System.Data.SqlClient.SqlConnection
Dim cmd As New System.Data.SqlClient.SqlCommand
cn.ConnectionString = "Password=brent;Persist Security
Info=True;User ID=sa;Initial Catalog=ee8idbbd;Data Source=JOMAR"
cn.Open()
cmd.Connection = cn
cmd.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
cmd.CommandText = "bdg_procFillSize"
Dim parm As New System.Data.SqlClient.SqlParameter
Dim parm1 As New System.Data.SqlClient.SqlParameter
'Dim parm As New System.Data.SqlClient.SqlParameter
parm.ParameterName = "@STYLE"
parm.SqlDbType = SqlDbType.VarChar
parm.Direction = ParameterDirection.Input
parm.Value = Me.STYLE.Text
cmd.Parameters.Add(parm)
parm1.ParameterName = "@COLOR"
parm1.SqlDbType = SqlDbType.VarChar
parm1.Direction = ParameterDirection.Input
'parm.Value = me.STYLE
parm1.Value = Me.DropDownList1.SelectedValue
'cmd.Parameters(0).Value = Me.STYLE.Text
cmd.Parameters.Add(parm1)

Dim rdr As System.Data.SqlClient.SqlDataReader =
cmd.ExecuteReader()
DropDownList2.DataSource = rdr
DropDownList2.DataTextField = "SIZECODE"
'DropDownList2.DataValueField = "SIZEINDEX"
DropDownList2.DataBind()
'rs = cmd.Execute
cn.Close()
'arrayvar = rs.GetRows
'cn.Close()
'cn = Nothing
'Dim i As Long
'For i = 0 To UBound(arrayvar, 2)
'Me.DropDownList1.Items.Add(New ListItem(arrayvar(0, i),
arrayvar(1, i)))
'Next
'arrayvar = rs.GetRows
'cn.Close()
'cn = Nothing
'Dim i As Long
'For i = 0 To UBound(arrayvar, 2)
'Me.DropDownList1.Items.Add(New ListItem(arrayvar(0, i),
arrayvar(1, i)))
'Next

End Sub

Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim cn As New System.Data.SqlClient.SqlConnection
Dim cmd As New System.Data.SqlClient.SqlCommand
cn.ConnectionString = "Password=brent;Persist Security
Info=True;User ID=sa;Initial Catalog=ee8idbbd;Data Source=JOMAR"
cn.Open()
cmd.Connection = cn
cmd.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
cmd.CommandText = "bdg_procTommyDixon"
Dim parm As New System.Data.SqlClient.SqlParameter
Dim parm1 As New System.Data.SqlClient.SqlParameter
Dim parm2 As New System.Data.SqlClient.SqlParameter
parm.ParameterName = "@STYLE"
parm.SqlDbType = SqlDbType.VarChar
parm.Direction = ParameterDirection.Input
parm.Value = Me.STYLE.SelectedValue
cmd.Parameters.Add(parm)

parm1.ParameterName = "@COLOR"
parm1.SqlDbType = SqlDbType.VarChar
parm1.Direction = ParameterDirection.Input
parm1.Value = Me.DropDownList1.SelectedValue

cmd.Parameters.Add(parm1)

parm2.ParameterName = "@SIZE"
parm2.SqlDbType = SqlDbType.VarChar
parm2.Direction = ParameterDirection.Input
parm2.Value = Me.DropDownList2.SelectedValue

cmd.Parameters.Add(parm2)
Dim rdr As System.Data.SqlClient.SqlDataReader =
cmd.ExecuteReader()
GridView1.DataSource = rdr
GridView1.DataBind()
cn.Close()

End Sub

Private Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim cn As New System.Data.SqlClient.SqlConnection
Dim cmd As New System.Data.SqlClient.SqlCommand
Dim rs As New ADODB.Recordset
'Dim arrayvar
cn.ConnectionString = "Password=brent;Persist Security
Info=True;User ID=sa;Initial Catalog=ee8idbbd;Data Source=JOMAR"
cn.Open()
cmd.Connection = cn
cmd.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
cmd.CommandText = "bdg_procFillColor"
Dim parm As New System.Data.SqlClient.SqlParameter
parm.ParameterName = "@STYLE"
parm.SqlDbType = SqlDbType.VarChar
parm.Direction = ParameterDirection.Input
parm.Value = Me.STYLE.SelectedValue
'cmd.Parameters(0).Value = Me.STYLE.Text
cmd.Parameters.Add(parm)
Dim rdr As System.Data.SqlClient.SqlDataReader =
cmd.ExecuteReader()
DropDownList1.DataSource = rdr
DropDownList1.DataValueField = "CODE"
DropDownList1.DataTextField = "COLOR"
DropDownList1.DataBind()
'rs = cmd.Execute
cn.Close()
'arrayvar = rs.GetRows
'cn.Close()
'cn = Nothing
'Dim i As Long
'For i = 0 To UBound(arrayvar, 2)
'Me.DropDownList1.Items.Add(New ListItem(arrayvar(0, i),
arrayvar(1, i)))
'Next
End Sub

Protected Sub STYLE_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
STYLE.SelectedIndexChanged

End Sub
End Class
 
B

Brent White

Thanks for all your help. I figured it out on my own. Next time I
won't bother.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top