//为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();

解决方案 »

  1.   

    while(dr.Read())
    {ListItem it =new ListItem();
    it.Value="李娜";
    it.Text=dr["truename"].ToString(); ListBox2.Items.Add(it);
    }
      

  2.   

    ListBox1.Items.Add(new ListItem("李娜","李娜");
      

  3.   

    listBox1.Items.Add(string key,string value);
    后面那个就是你所指的value,如果不指定的话就是默认的和key 值相同的
      

  4.   

    可以
    while(dr.Read())
    {
        ListItem item=new ListItem();
        item.Value="你想要的值";
        item.Text=dr["truename"].ToString();
        ListBox2.Items.Add(item);
    }
      

  5.   

    ListBox1.Items.Add(new ListItem("李娜","李娜");
      

  6.   

    抛砖引玉一下TableList.DataSource = dt.DefaultView;//绑定数据源
    TableList.DisplayMember = dt.Columns[0].ToString();//绑定要显示的字段注:TableList是一个类似控件
      

  7.   

    要是在Windows下又怎么办呢??