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();
    ************
  • 相关阅读:
    Cygwin 与 MinGW/MSYS/MSYS2,如何选择?甚至还有GNU utilities for Win32
    MinGW和MSYS项目是在一起的(翻译官网)
    库存限购
    ElasticSearch指南
    Windows系统的Jenkins持续集成环境
    JavaScript 框架
    Istio Service Mash管理微服务
    LinkedIn微服务框架rest.li
    Istio微服务架构初试
    github
  • 原文地址:https://www.cnblogs.com/zjw/p/1233584.html
Copyright © 2011-2022 走看看