asp.net中c#里如何用Dropdownlist 现在我将数据库里得一个权限名字段绑定到Dropdownlist里,我数据库中有两个表 第一个表 就是员工表 里面有名字,密码,权限号字段,第二张表有权限号,和权限名字段,现在获取权限号,把增加员工得信息加到第一张表去,怎么获取选择权限名得权限号?在线等回复!谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你绑定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 this.DropDownList1.DataTextField = "权限名";this.DropDownList1.DataValueField = "权限号"; 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(); 是否忘记添加if(!this.IsPostBack) { } “没有权限”问题 web网站下载图片到手机 请问为什么vwd2008会生成这么怪的SQL呢? 关于命名空间的问题 请问在ASP.NET如何输出SQL查询语句的值? 问关于DataGrid中绑定Dropdownlist的问题 条形码问题,再线等,解决就给分 datagrid模版列点击“更新”没有作用 至今没解决的难题 如何才能浏览记录,例如“第一个”“下一个”“上一个”“最后一个” 一个数据统计分析方面的疑问! 如何更改这个程序错误
可以作个联合查询
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
this.DropDownList1.DataValueField = "权限号";
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();
{
}