Dropdown list problem

J

JJ297

I have a dropdown on the page and a check box list:

User selects a title from the dropdown and then the check box list has
info that's in the data base that's associated with that title checks
in the box.

Here's the dropdown list:

<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1"

DataTextField="Title" DataValueField="TitleID" AutoPostBack="true"
AppendDataBoundItems="True"><asp:ListItem Value="Select a Title">

Select a Title</asp:ListItem>

</asp:DropDownList>&nbsp;<br />

<asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataSourceID="SqlDataSource2"

DataTextField="description" DataValueField="classificationid"
BorderStyle="Solid"

BorderWidth="2px" CellPadding="6" CellSpacing="1" Height="123px"
RepeatColumns="1" Width="203px" BorderColor="#CFB37D" Font-Bold="True"
TextAlign="Left" style="text-align: right" AutoPostBack="True">

</asp:CheckBoxList></center>

If I select a title from the dropdown that has titles checked in the
database it appears but if I make a change from the dropdown to
another title the check box list still is only showing what the
previous selection was. Does anyone know what I'm doing wrong?

Here's the code behind page:

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChangedDim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("TrainUserConnectionString").ConnectionString)


Dim cmdcheckboxlist As New Data.SqlClient.SqlCommand

With cmdcheckboxlist
cmdcheckboxlist.CommandType = Data.CommandType.StoredProcedure

cmdcheckboxlist.CommandText = "GetClassID"

cmdcheckboxlist.Parameters.AddWithValue("@titleId",
DropDownList1.SelectedValue)
cmdcheckboxlist.Connection = conn

conn.Open()

cmdcheckboxlist.ExecuteNonQuery()

End With

Dim sqldatareader As SqlDataReader
sqldatareader = cmdcheckboxlist.ExecuteReader()

While (sqldatareader.Read()) Dim currentListItem As ListItem =
CheckBoxList1.Items.FindByValue(sqldatareader("classificationid").ToString())
If (Not IsNothing(currentListItem)) Then

currentListItem.Selected = True

End If

End While

End Sub

Any suggestions?



Select Tags... SaveCancel


[Edit Tags]
 

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

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,696
Latest member
BarbraOLog

Latest Threads

Top