26
2012
04

Asp.Net 如何DropdownList读取值,并使用JS通过ID赋值

        public void GetCustomerGroup()
        {
            try
            {
                CustomerInterface customerBLL = CustomerProvider.GetDAL();
                DataTable table = customerBLL.GetCustomerGroup(userAccount.UserAccountID);

                DropDownList1.Items.Clear();

                ListItem items1 = new ListItem();
                items1.Value = "";
                items1.Text = "全部";
                DropDownList1.Items.Add(items1);

                if (table != null && table.Rows.Count > 0)
                {
                    div = "<dl>";
                    if (table != null && table.Rows.Count > 0)
                    {
                        foreach (DataRow dr in table.Rows)
                        {

                            ListItem items = new ListItem();
                            items.Value = dr[0].ToString();
                            items.Text = dr[1].ToString();
                            DropDownList1.Items.Add(items);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Page, "读取错误!");
            }
            finally
            {
            }
        }

    function clickBtnGrop(dropID) {

        setListValue("DropDownList1", dropID);
    }

    function setListValue(listName, txtValue) {
        var objList = document.getElementById(listName);
        for (var i = 0; i < objList.options.length; i++) {
            if (objList.options[i].value == txtValue) {
                objList.options[i].selected = true;
                break;
            }
        }
    }

« 上一篇下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。