您的位置:首页 > 运维架构

无误选择列表项的值或文本 listbox,dropdownlist,radiobuttonlist 函数

2008-12-02 14:37 302 查看
//选中选项
public void SelectListIndex(ref ListControl wc, string textOrValue, bool isText)
{

string tempType = wc.GetType().ToString();
tempType = tempType.Replace("System.Web.UI.WebControls.", "").ToLower();
if (tempType == "listbox")
{
if (isText)
((ListBox)wc).SelectedIndex = ((ListBox)wc).Items.IndexOf(((ListBox)wc).Items.FindByText(textOrValue));
else
((ListBox)wc).SelectedIndex = ((ListBox)wc).Items.IndexOf(((ListBox)wc).Items.FindByValue(textOrValue));

}
else if (tempType == "dropdownlist")
{

if (isText)
((DropDownList)wc).SelectedIndex = ((DropDownList)wc).Items.IndexOf(((DropDownList)wc).Items.FindByText(textOrValue));
else
((DropDownList)wc).SelectedIndex = ((DropDownList)wc).Items.IndexOf(((DropDownList)wc).Items.FindByValue(textOrValue));

}
else if (tempType == "radiobuttonlist")
{

if (isText)
((RadioButtonList)wc).SelectedIndex = ((RadioButtonList)wc).Items.IndexOf(((RadioButtonList)wc).Items.FindByText(textOrValue));
else
((RadioButtonList)wc).SelectedIndex = ((RadioButtonList)wc).Items.IndexOf(((RadioButtonList)wc).Items.FindByValue(textOrValue));

}
}

谢谢大家的支持,帮我点下需要的广告谢谢我会更加努力整理我的百科服务大家
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐