C#技术百科
问问你的心你有没有信心 做事情要专一坚定,执着

//选中选项
        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));

        
            }
        }

谢谢大家的支持,帮我点下需要的广告谢谢我会更加努力整理我的百科服务大家
posted on 2008-12-02 14:37  王德田  阅读(272)  评论(0编辑  收藏  举报