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.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim cn As New System.Data.Sql Client.SqlConne ction
Dim cmd As New System.Data.Sql Client.SqlComma nd
cn.ConnectionSt ring = "Password=;Pers ist Security
Info=True;User ID=sa;Initial Catalog=BadgerB lue;Data
Source=195.1.2. 222"
cn.Open()
cmd.Connection = cn
cmd.CommandType = ADODB.CommandTy peEnum.adCmdTex t
cmd.CommandText = "SELECT DISTINCT STYLE FROM BBHOLD"
Dim rdr As System.Data.Sql Client.SqlDataR eader =
cmd.ExecuteRead er()
Me.STYLE.DataSo urce = rdr
Me.STYLE.DataTe xtField = "STYLE"
Me.STYLE.DataVa lueField = "STYLE"
Me.STYLE.DataBi nd()
cn.Close()
End Sub
Private Sub DropDownList1_T extChanged(ByVa l sender As Object,
ByVal e As System.EventArg s) Handles DropDownList1.T extChanged
'Response.Write ((DropDownList1 .SelectedValue) )
Dim cn As New System.Data.Sql Client.SqlConne ction
Dim cmd As New System.Data.Sql Client.SqlComma nd
cn.ConnectionSt ring = "Password=brent ;Persist Security
Info=True;User ID=sa;Initial Catalog=ee8idbb d;Data Source=JOMAR"
cn.Open()
cmd.Connection = cn
cmd.CommandType = ADODB.CommandTy peEnum.adCmdSto redProc
cmd.CommandText = "bdg_procFillSi ze"
Dim parm As New System.Data.Sql Client.SqlParam eter
Dim parm1 As New System.Data.Sql Client.SqlParam eter
'Dim parm As New System.Data.Sql Client.SqlParam eter
parm.ParameterN ame = "@STYLE"
parm.SqlDbType = SqlDbType.VarCh ar
parm.Direction = ParameterDirect ion.Input
parm.Value = Me.STYLE.Text
cmd.Parameters. Add(parm)
parm1.Parameter Name = "@COLOR"
parm1.SqlDbType = SqlDbType.VarCh ar
parm1.Direction = ParameterDirect ion.Input
'parm.Value = me.STYLE
parm1.Value = Me.DropDownList 1.SelectedValue
'cmd.Parameters (0).Value = Me.STYLE.Text
cmd.Parameters. Add(parm1)
Dim rdr As System.Data.Sql Client.SqlDataR eader =
cmd.ExecuteRead er()
DropDownList2.D ataSource = rdr
DropDownList2.D ataTextField = "SIZECODE"
'DropDownList2. DataValueField = "SIZEINDEX"
DropDownList2.D ataBind()
'rs = cmd.Execute
cn.Close()
'arrayvar = rs.GetRows
'cn.Close()
'cn = Nothing
'Dim i As Long
'For i = 0 To UBound(arrayvar , 2)
'Me.DropDownLis t1.Items.Add(Ne w ListItem(arrayv ar(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.DropDownLis t1.Items.Add(Ne w ListItem(arrayv ar(0, i),
arrayvar(1, i)))
'Next
End Sub
Protected Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button1.Click
Dim cn As New System.Data.Sql Client.SqlConne ction
Dim cmd As New System.Data.Sql Client.SqlComma nd
cn.ConnectionSt ring = "Password=brent ;Persist Security
Info=True;User ID=sa;Initial Catalog=ee8idbb d;Data Source=JOMAR"
cn.Open()
cmd.Connection = cn
cmd.CommandType = ADODB.CommandTy peEnum.adCmdSto redProc
cmd.CommandText = "bdg_procTommyD ixon"
Dim parm As New System.Data.Sql Client.SqlParam eter
Dim parm1 As New System.Data.Sql Client.SqlParam eter
Dim parm2 As New System.Data.Sql Client.SqlParam eter
parm.ParameterN ame = "@STYLE"
parm.SqlDbType = SqlDbType.VarCh ar
parm.Direction = ParameterDirect ion.Input
parm.Value = Me.STYLE.Select edValue
cmd.Parameters. Add(parm)
parm1.Parameter Name = "@COLOR"
parm1.SqlDbType = SqlDbType.VarCh ar
parm1.Direction = ParameterDirect ion.Input
parm1.Value = Me.DropDownList 1.SelectedValue
cmd.Parameters. Add(parm1)
parm2.Parameter Name = "@SIZE"
parm2.SqlDbType = SqlDbType.VarCh ar
parm2.Direction = ParameterDirect ion.Input
parm2.Value = Me.DropDownList 2.SelectedValue
cmd.Parameters. Add(parm2)
Dim rdr As System.Data.Sql Client.SqlDataR eader =
cmd.ExecuteRead er()
GridView1.DataS ource = rdr
GridView1.DataB ind()
cn.Close()
End Sub
Private Sub Button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button2.Click
Dim cn As New System.Data.Sql Client.SqlConne ction
Dim cmd As New System.Data.Sql Client.SqlComma nd
Dim rs As New ADODB.Recordset
'Dim arrayvar
cn.ConnectionSt ring = "Password=brent ;Persist Security
Info=True;User ID=sa;Initial Catalog=ee8idbb d;Data Source=JOMAR"
cn.Open()
cmd.Connection = cn
cmd.CommandType = ADODB.CommandTy peEnum.adCmdSto redProc
cmd.CommandText = "bdg_procFillCo lor"
Dim parm As New System.Data.Sql Client.SqlParam eter
parm.ParameterN ame = "@STYLE"
parm.SqlDbType = SqlDbType.VarCh ar
parm.Direction = ParameterDirect ion.Input
parm.Value = Me.STYLE.Select edValue
'cmd.Parameters (0).Value = Me.STYLE.Text
cmd.Parameters. Add(parm)
Dim rdr As System.Data.Sql Client.SqlDataR eader =
cmd.ExecuteRead er()
DropDownList1.D ataSource = rdr
DropDownList1.D ataValueField = "CODE"
DropDownList1.D ataTextField = "COLOR"
DropDownList1.D ataBind()
'rs = cmd.Execute
cn.Close()
'arrayvar = rs.GetRows
'cn.Close()
'cn = Nothing
'Dim i As Long
'For i = 0 To UBound(arrayvar , 2)
'Me.DropDownLis t1.Items.Add(Ne w ListItem(arrayv ar(0, i),
arrayvar(1, i)))
'Next
End Sub
Protected Sub STYLE_SelectedI ndexChanged(ByV al sender As
System.Object, ByVal e As System.EventArg s) Handles
STYLE.SelectedI ndexChanged
End Sub
End Class
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.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim cn As New System.Data.Sql Client.SqlConne ction
Dim cmd As New System.Data.Sql Client.SqlComma nd
cn.ConnectionSt ring = "Password=;Pers ist Security
Info=True;User ID=sa;Initial Catalog=BadgerB lue;Data
Source=195.1.2. 222"
cn.Open()
cmd.Connection = cn
cmd.CommandType = ADODB.CommandTy peEnum.adCmdTex t
cmd.CommandText = "SELECT DISTINCT STYLE FROM BBHOLD"
Dim rdr As System.Data.Sql Client.SqlDataR eader =
cmd.ExecuteRead er()
Me.STYLE.DataSo urce = rdr
Me.STYLE.DataTe xtField = "STYLE"
Me.STYLE.DataVa lueField = "STYLE"
Me.STYLE.DataBi nd()
cn.Close()
End Sub
Private Sub DropDownList1_T extChanged(ByVa l sender As Object,
ByVal e As System.EventArg s) Handles DropDownList1.T extChanged
'Response.Write ((DropDownList1 .SelectedValue) )
Dim cn As New System.Data.Sql Client.SqlConne ction
Dim cmd As New System.Data.Sql Client.SqlComma nd
cn.ConnectionSt ring = "Password=brent ;Persist Security
Info=True;User ID=sa;Initial Catalog=ee8idbb d;Data Source=JOMAR"
cn.Open()
cmd.Connection = cn
cmd.CommandType = ADODB.CommandTy peEnum.adCmdSto redProc
cmd.CommandText = "bdg_procFillSi ze"
Dim parm As New System.Data.Sql Client.SqlParam eter
Dim parm1 As New System.Data.Sql Client.SqlParam eter
'Dim parm As New System.Data.Sql Client.SqlParam eter
parm.ParameterN ame = "@STYLE"
parm.SqlDbType = SqlDbType.VarCh ar
parm.Direction = ParameterDirect ion.Input
parm.Value = Me.STYLE.Text
cmd.Parameters. Add(parm)
parm1.Parameter Name = "@COLOR"
parm1.SqlDbType = SqlDbType.VarCh ar
parm1.Direction = ParameterDirect ion.Input
'parm.Value = me.STYLE
parm1.Value = Me.DropDownList 1.SelectedValue
'cmd.Parameters (0).Value = Me.STYLE.Text
cmd.Parameters. Add(parm1)
Dim rdr As System.Data.Sql Client.SqlDataR eader =
cmd.ExecuteRead er()
DropDownList2.D ataSource = rdr
DropDownList2.D ataTextField = "SIZECODE"
'DropDownList2. DataValueField = "SIZEINDEX"
DropDownList2.D ataBind()
'rs = cmd.Execute
cn.Close()
'arrayvar = rs.GetRows
'cn.Close()
'cn = Nothing
'Dim i As Long
'For i = 0 To UBound(arrayvar , 2)
'Me.DropDownLis t1.Items.Add(Ne w ListItem(arrayv ar(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.DropDownLis t1.Items.Add(Ne w ListItem(arrayv ar(0, i),
arrayvar(1, i)))
'Next
End Sub
Protected Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button1.Click
Dim cn As New System.Data.Sql Client.SqlConne ction
Dim cmd As New System.Data.Sql Client.SqlComma nd
cn.ConnectionSt ring = "Password=brent ;Persist Security
Info=True;User ID=sa;Initial Catalog=ee8idbb d;Data Source=JOMAR"
cn.Open()
cmd.Connection = cn
cmd.CommandType = ADODB.CommandTy peEnum.adCmdSto redProc
cmd.CommandText = "bdg_procTommyD ixon"
Dim parm As New System.Data.Sql Client.SqlParam eter
Dim parm1 As New System.Data.Sql Client.SqlParam eter
Dim parm2 As New System.Data.Sql Client.SqlParam eter
parm.ParameterN ame = "@STYLE"
parm.SqlDbType = SqlDbType.VarCh ar
parm.Direction = ParameterDirect ion.Input
parm.Value = Me.STYLE.Select edValue
cmd.Parameters. Add(parm)
parm1.Parameter Name = "@COLOR"
parm1.SqlDbType = SqlDbType.VarCh ar
parm1.Direction = ParameterDirect ion.Input
parm1.Value = Me.DropDownList 1.SelectedValue
cmd.Parameters. Add(parm1)
parm2.Parameter Name = "@SIZE"
parm2.SqlDbType = SqlDbType.VarCh ar
parm2.Direction = ParameterDirect ion.Input
parm2.Value = Me.DropDownList 2.SelectedValue
cmd.Parameters. Add(parm2)
Dim rdr As System.Data.Sql Client.SqlDataR eader =
cmd.ExecuteRead er()
GridView1.DataS ource = rdr
GridView1.DataB ind()
cn.Close()
End Sub
Private Sub Button2_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button2.Click
Dim cn As New System.Data.Sql Client.SqlConne ction
Dim cmd As New System.Data.Sql Client.SqlComma nd
Dim rs As New ADODB.Recordset
'Dim arrayvar
cn.ConnectionSt ring = "Password=brent ;Persist Security
Info=True;User ID=sa;Initial Catalog=ee8idbb d;Data Source=JOMAR"
cn.Open()
cmd.Connection = cn
cmd.CommandType = ADODB.CommandTy peEnum.adCmdSto redProc
cmd.CommandText = "bdg_procFillCo lor"
Dim parm As New System.Data.Sql Client.SqlParam eter
parm.ParameterN ame = "@STYLE"
parm.SqlDbType = SqlDbType.VarCh ar
parm.Direction = ParameterDirect ion.Input
parm.Value = Me.STYLE.Select edValue
'cmd.Parameters (0).Value = Me.STYLE.Text
cmd.Parameters. Add(parm)
Dim rdr As System.Data.Sql Client.SqlDataR eader =
cmd.ExecuteRead er()
DropDownList1.D ataSource = rdr
DropDownList1.D ataValueField = "CODE"
DropDownList1.D ataTextField = "COLOR"
DropDownList1.D ataBind()
'rs = cmd.Execute
cn.Close()
'arrayvar = rs.GetRows
'cn.Close()
'cn = Nothing
'Dim i As Long
'For i = 0 To UBound(arrayvar , 2)
'Me.DropDownLis t1.Items.Add(Ne w ListItem(arrayv ar(0, i),
arrayvar(1, i)))
'Next
End Sub
Protected Sub STYLE_SelectedI ndexChanged(ByV al sender As
System.Object, ByVal e As System.EventArg s) Handles
STYLE.SelectedI ndexChanged
End Sub
End Class
Comment