473,507 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Constructing ASP in VS2005. One dropdownlist control will notcooperate

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
Jun 27 '08 #1
1 1210
Thanks for all your help. I figured it out on my own. Next time I
won't bother.
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
16975
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
18
2423
by: Julia Hu | last post by:
Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and load data into these controls. For example,in the first row I need to bind data into a...
10
5286
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
17
2548
by: Samuel | last post by:
Hi All, I am in the process of converting a VS 2003 project to VS 2005 project (VB.NET Class Library). It gives the error in TypeOf and DirectCast statements. It was working...
0
252
by: postings | last post by:
Hi This is (more or less) a repost from last week. Sorry I'm pretty despirate for a soltution and hope I get better luck this time! Would you mind looking at this? - Thanks.... The code below...
5
1657
by: Charts | last post by:
I recently upgraded to VS2005. I noticed that in ASP.NET project, the system generated codes are missing from default.aspx.cs file. While I used to be able to see it in VS2003 project. Now, if I...
15
3076
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
0
1975
by: Marek | last post by:
I have DetialsView control and DropDownList control on the same page. I use DropDownList.SelectedVlue as key for DetailsView control. I use SELECT ... FROM table WHERE id_kont = @id_kont where...
0
1050
by: Marek | last post by:
Hi all, I have GridView control placed on given page. This control has DataSource attached to it with select and update commands. One column is teplate field (DropDownList control). This control...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.