现在我将数据库里得一个权限名字段绑定到Dropdownlist里,我数据库中有两个表 第一个表 就是员工表 里面有名字,密码,权限号字段,第二张表有权限号,和权限名字段,现在获取权限号,把增加员工得信息加到第一张表去,怎么获取选择权限名得权限号?在线等回复!谢谢

解决方案 »

  1.   

    你绑定Dropdownlist的时候就应该同时绑定权限名和权限号
    可以作个联合查询
    string sql="select * from 表1 left union 表2 on 表1.权限号=表2.权限号";
    然后将查处的数据放到DataTable dt中
    this.DropDownList.DataSource = dt.DefaultView;
    this.DropDownList.DataTextField = "权限名";
    this.DropDownList.DataValueField = "权限号";
    this.DropDownList.DataBind();
    用的时候
    用权限号的时候this.DropDownList.SelectedValue
    用权限名的时候this.DropDownList.SelectedItem.Text
      

  2.   

    this.DropDownList1.DataTextField = "权限名";
    this.DropDownList1.DataValueField = "权限号";
      

  3.   

    System.Data.SqlClient.SqlDataAdapter ds = new SqlDataAdapter();
    System.Data.SqlClient.SqlCommand con = new SqlCommand();
    System.Data.DataTable dt = new DataTable();
    string strQuery;ds.SelectCommand = con;
    con.Connection = this.conn;strQuery = "select distinct 列名 as TextField, 列名 as ValueField from 表名 where 条件";
    con.CommandText = strQuery;
    ds.Fill(dt); this.DropDownList.DataSource = dt.DefaultView;
    this.DropDownList.DataTextField = "TextField";
    this.DropDownList.DataValueField = "ValueField";
    this.DropDownList.DataBind();
      

  4.   

    是否忘记添加if(!this.IsPostBack)
    {
    }