DropDownList1.DataSource=ds.Tables["types"].DefaultView;
DropDownList1.DataTextFiels="typename";
DropDownList1.DataValueField="id";
DropDownList1.DataBind();
中DropDownList1.DataValueField="id";
其中DataValueField是这个Text对应的值
可以使用
DropDownList1.SelectItem.Value;
DropDownList1.SelectItem.Text;

解决方案 »

  1.   

    我个人认为这样绑定是很麻烦的,为什么不写一个公用函数用来绑定所有的DropDownList呢!
      

  2.   

    Public Function InitDDL(Byval DDL as DropDownList,Byval SQl as String,Byval Value as String,Byval Text as String)
       ddl.items.clear()
          Dim Item1 as New ListItem()
          Item1.Text="All" 
          Item1.Value="0"
       ddl.items.add(Item1)
       Dim ConStr as String="data source=127.0.0.1;initial catalog=GVS;Connect       Timeout=500000;user id=sa;password=""
       Dim MyCon as SqlConnection=New SqlConnection(ConStr)
       Dim MyCom as SqlCommand=New SqlCommand(SQl,MyCon)
          MyCon.Open()
          Dim Reader As SqlDataReader
          Reader=MyCom.ExecuteReader
       While Reader.Read()
          Dim Item As New ListItem()
          IF Not IsDbNull(Reader(Text)) Then
             IF Trim(Reader(Text))<>"" Then
                Item.Text=Reader(Text)
             Else 
                Item.Text=""
             End IF
           Else
              Item.Text=""
           End IF
           IF Not IsDbNull(Reader(Value)) Then
              IF Trim(Reader(Value))<>"" Then
                 Item.Value=Reader(Value)
              Else
                 Item.Value=""
              End IF
           Else
              Item.Value=""
           End IF
           ddl.items.add(item)
       End While
       Reader.Close()
       Reader=Nothing
       MyCon.Close()
       MyCon=Nothing
    End Function
    利用这一个公用函数就可以绑定所有的DropDownList了,你知需要给它的四个参数赋值就可以了!
      

  3.   

    楼主: DataTextFiels 绑定的是显示文本
    DataValueField 绑定的是值
    wuqiwhy(水手&菜鸟) 没有必要