• 下拉框数据绑定两种方式


    1、利用cs包,DataAccess.cs

    #region
    string m_str = @"select sname from service group by sname";
    DataTable m_dt = DataAccess.DBHelper.GetList(m_str);
    DropDownList2.DataValueField = "sname";
    DropDownList2.DataTextField = "sname";
    绑定数据源
    this.DropDownList2.DataSource = m_dt;
    DropDownList2.DataBind();
    
    DropDownList2.Items.Insert(0, new ListItem("请选择", ""));
    #endregion

    而在web.config中

    <appSettings>
        <!--数据库连接字符串-->
        <add key="DBConnString" value="Data Source=localhost;database=manager;uid=sa;pwd=sa;" />
      </appSettings>

    2、

    SqlConnection conn = new SqlConnection("Data Source = localhost; database = manager; uid=sa; pwd=sa;");
            conn.Open();
    
            //任务类型绑定
            #region
            SqlDataAdapter sdt = new SqlDataAdapter("select sname from service group by sname", conn);
    
            DataSet dt = new DataSet();
            sdt.Fill(dt);
            DropDownList2.DataValueField = "sname";
            DropDownList2.DataTextField = "sname";
            this.DropDownList2.DataSource = dt;
            DropDownList2.DataBind();
    
            DropDownList2.Items.Insert(0, new ListItem("请选择", ""));
            #endregion
            conn.Close();

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    C# 字符串转为DateTime类型
    多线程的注意事项
    linux 安装中文支持
    发布网站遇到的坑
    配置iis支持json解析,配置ssi
    SEO之图片优化
    SEO之面包屑导航
    SEO之HTML标签
    SEO之优化代码
    SEO之网站内部结构优化
  • 原文地址:https://www.cnblogs.com/PearlRan/p/4833063.html
Copyright © 2020-2023  润新知