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();
    ************
  • 相关阅读:
    thinkphp中<eq>标签的使用
    Thinkphp中的eq比较标签
    select取数据库值设为默认值,TP框架模板中ifelse
    fastadmin 前端根据status自定义显示不同的内容
    CMS自定义表单无法切换“是否需要登录”开关
    js获取域名
    fastadmin 页面添加编辑日期时间
    bootstrap-table给单元格添加链接
    python相关资料
    区块链共识机制 —— PoW共识的Python实现
  • 原文地址:https://www.cnblogs.com/zjw/p/1233584.html
Copyright © 2011-2022 走看看