Reputation: 460
i have the control:
<asp:CheckBoxList ID="CheckBoxListdepts" AutoPostBack="true" BorderWidth="1PX" BorderColor="#3f3a71" Width="100%" runat="server"
DataSourceID="SqlDataSourcedepts"
DataTextField="dept_name"
DataValueField="dept_id"
OnSelectedIndexChanged="CheckBoxListdepts_SelectedIndexChanged">
i have an array of 5 CheckBoxList and this is my code
protected void CheckBoxListdepts_SelectedIndexChanged(object sender, EventArgs e)
{
CheckBoxList[] mylists = { CheckBoxList1, CheckBoxList2, CheckBoxList3, CheckBoxList4, CheckBoxList5 };
for (int i = 0; i < 5; i++)
{
mylists[i].DataSource = (from ListItem rr in CheckBoxListdepts.Items
where rr.Selected == true
select rr);
mylists[i].DataBind();
}
}
the problem is when i try to get the selected value from checkbox1list1 i got selectedText instead like this:
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label7.Text = CheckBoxList1.SelectedItem.Value.ToString();
}
i got the SelectedText why "rr" lost its value property?
Upvotes: 0
Views: 41
Reputation: 73761
I don't know what your 5 CheckBoxLists look like, but I think that you must set their DataValueField and DataTextField properties to get what you want:
<asp:CheckBoxList1 runat="server" DataValueField="Value" DataTextField="Text" />
Upvotes: 1