选择清单列表中的下拉列表项是否已选中? [英] select dropdownlist item is checked in checkedlistbox?
本文介绍了选择清单列表中的下拉列表项是否已选中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
先生,
在我的Web应用程序中,我被选中了一个dropdownlist,button和chekboxList控件.下拉列表中的项目是红色,蓝色,绿色.
并且在清单框中,我拿到的物品是
hi sir,
in my web app i am taken one dropdownlist, button and chekboxList controls. and in dropdownlist items are Red, Blue, Green.
and in checkedlistbox i take items are
<asp:CheckBoxList ID="CheckBoxList1" runat="Server">
<asp:ListItem Text="Red" Value="red"></asp:ListItem>
<asp:ListItem Text="Blue" Value="blue"></asp:ListItem>
<asp:ListItem Text="Green" Value="green"></asp:ListItem>
</asp:CheckBoxList>
我的目标是当我在下拉列表中选择红色"项目,并且单击红色"复选框时被选中的按钮.类似于所有
请给我一个解决方案,并请提供一些示例代码来做到这一点.
谢谢
my aim is when i am selecting Red item in dropdownlist and i click button that time Red checkbox is selected. similarly to all
please give me a solution and please give a some sample code todo this.
Thanks
推荐答案
使用以下代码..数组列表将保留复选框列表控件中的选定"复选框值
Use the below code .. the array list will hold the Selected check box value from checkbox list control
ArrayList arrList = new ArrayList();
for(int i=0;i<=CheckBoxList1.Items.Count -1;i++)
{
if (CheckBoxList1.Items[i].Selected)
{
arrList.Add(CheckBoxList1.Items[i].Value);
}
}
}
选中此
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].ToString() == DropDownList1.SelectedItem.Text)
{
CheckBoxList1.Items[i].Selected = true;
break;
}
}
}
这篇关于选择清单列表中的下拉列表项是否已选中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文