public static void SetListBoxItem(ListBox listBox, string sItemValue)
{
int index = 0;
foreach (ListItem item in listBox.Items)
{
///判断值是否相等,并且设置控件的SelectedIndex
if (item.Value.ToLower() == sItemValue.ToLower())
{
listBox.SelectedIndex = index;
break;
}
index++;
}
}
public static void SetListBoxItem(DropDownList listBox, string sItemValue)
{
int index = 0;
foreach (ListItem item in listBox.Items)
{
///判断值是否相等,并且设置控件的SelectedIndex
if (item.Value.ToLower() == sItemValue.ToLower())
{
listBox.SelectedIndex = index;
break;
}
index++;
}
}
public static void SetListBoxItem(ListBox listBox, string sItemValue, bool IsBool)
{
int index = 0;
if (IsBool == true)
{
sItemValue = sItemValue.ToLower() == "true" ? "1" : "0";
}
foreach (ListItem item in listBox.Items)
{
///判断值是否相等,并且设置控件的SelectedIndex
if (item.Value.ToLower() == sItemValue.ToLower())
{
listBox.SelectedIndex = index;
break;
}
index++;
}
}
public static void SetListBoxItem(DropDownList listBox, string sItemValue, bool IsBool)
{
int index = 0;
if (IsBool == true)
{
sItemValue = sItemValue.ToLower() == "true" ? "1" : "0";
}
foreach (ListItem item in listBox.Items)
{
///判断值是否相等,并且设置控件的SelectedIndex
if (item.Value.ToLower() == sItemValue.ToLower())
{
listBox.SelectedIndex = index;
break;
}
index++;
}
}
遍历 DropDownList ListBox
最新推荐文章于 2022-06-01 21:54:26 发布