//为ListBox2绑定数据
string sql = "select truename,FingerPrintNo from FingerPrint_MessageTable where Enabled=1 and DepartMent='"+ListBox1.SelectedValue.ToString()+"'" ;
Label1.Text=sql;
SqlConnection Connection = new SqlConnection(ConfigurationSettings.AppSettings["Conn_FingerKeeper"]);
SqlCommand thisCommand = new SqlCommand ( sql,Connection );try
{
//打开数据库连接
thisCommand.Connection.Open();
//执行SQL语句,并返回DataReader对象
SqlDataReader dr = thisCommand.ExecuteReader();
//循环读取结果集并加入ListBox2while(dr.Read())
{
ListBox2.Items.Add(dr["truename"].ToString());
===================================
上面一句可以完成<option value="李娜">李娜</option>,但我想让value与显示
的内容不一样,怎么办?可以添加“<option value="李娜">李娜</option>”中value的值吗?===================================}
dr.Close();
string sql = "select truename,FingerPrintNo from FingerPrint_MessageTable where Enabled=1 and DepartMent='"+ListBox1.SelectedValue.ToString()+"'" ;
Label1.Text=sql;
SqlConnection Connection = new SqlConnection(ConfigurationSettings.AppSettings["Conn_FingerKeeper"]);
SqlCommand thisCommand = new SqlCommand ( sql,Connection );try
{
//打开数据库连接
thisCommand.Connection.Open();
//执行SQL语句,并返回DataReader对象
SqlDataReader dr = thisCommand.ExecuteReader();
//循环读取结果集并加入ListBox2while(dr.Read())
{
ListBox2.Items.Add(dr["truename"].ToString());
===================================
上面一句可以完成<option value="李娜">李娜</option>,但我想让value与显示
的内容不一样,怎么办?可以添加“<option value="李娜">李娜</option>”中value的值吗?===================================}
dr.Close();
{ListItem it =new ListItem();
it.Value="李娜";
it.Text=dr["truename"].ToString(); ListBox2.Items.Add(it);
}
后面那个就是你所指的value,如果不指定的话就是默认的和key 值相同的
while(dr.Read())
{
ListItem item=new ListItem();
item.Value="你想要的值";
item.Text=dr["truename"].ToString();
ListBox2.Items.Add(item);
}
TableList.DisplayMember = dt.Columns[0].ToString();//绑定要显示的字段注:TableList是一个类似控件