zoukankan      html  css  js  c++  java
  • DropDownlist编程问题

    <body>
    <form id="form1" runat="server">
    <div>
    <asp:DropDownList ID="DropDownList1" runat="server"

    AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
    </asp:DropDownList>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
    </form>
    </body>
    ===============

    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.DropDownList1.DataSource = //从数据库区的dataSet
            this.DropDownList1.DataTextField = "姓名";
            this.DropDownList1.DataValueField = "籍贯";
            this.DropDownList1.DataBind();
        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string str = this.DropDownList1.SelectedValue; //这行重要..... 取选的项的值.
            if(str == null || str.Length==0)
            {
                str = this.DropDownList1.Items[0].Value;
            }
            this.TextBox1.Text = str;
        }
    }
    ****************************
    ----- 下面是另一种方法
    动态绑定数据库中的字段。
    C#代码

       1. SqlConnection conn = UtilitySqlClass.OperateDataBase.ReturnConn();
       2. string strSQL = "select * from CompanyType";
       3. SqlDataAdapter ada = new SqlDataAdapter(strSQL, conn);
       4. DataSet ds = new DataSet();
       5. ada.Fill(ds, "CompanyType");
       6. DropDownList1.DataSource = ds.Tables["CompanyType"].DefaultView;
       7.
    DropDownList1.DataValueField = ds.Tables["CompanyType"].Columns[1].ColumnName; //就是为了看这行......
       8. DropDownList1.DataTextField = ds.Tables["CompanyType"].Columns[1].ColumnName;
       9. DropDownList1.DataBind();
    10. ds.Dispose();
    ************
  • 相关阅读:
    leetcode: Combination Sum II
    leetcode: Combination Sum
    leetcode: Count and Say
    leetcode: Sudoku Solver
    leetcode: Linked List Cycle II
    selenium采用xpath方法识别页面元素
    selenium采用find_element_by方法识别页面元素
    selenium中webdriver识别class属性多个值中有空格的解决方案
    解决多个py模块调用同一个python的logging模块,打印日志冲突问题
    封装selenium自动化框架中的截图功能
  • 原文地址:https://www.cnblogs.com/zjw/p/1233584.html
Copyright © 2011-2022 走看看