Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

Constructing ASP in VS2005.  One dropdownlist control will not     cooperate

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brent White - 14 Apr 2008 16:43 GMT
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
Brent White - 21 Apr 2008 06:58 GMT
Thanks for all your help.  I figured it out on my own.  Next time I
won't bother.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.