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:
<aspropDownList 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>
</aspropDownList> <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]
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:
<aspropDownList 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>
</aspropDownList> <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]