注册 登录
编程论坛 ASP.NET技术论坛

求助:怎样取到dropdownlist的值?

高手如云1 发布于 2011-11-17 22:36, 949 次点击
第一个dropdownlist是数据库绑定的。相关代码如下:
   <td bgcolor="#FFFFFF"><% DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(DataSet1.FieldValue("ID", Nothing)  )) %><asp:DropDownList ID="DropDownList1" runat="server" DataTextField="years" DataValueField="ID" DataSource='<%# DataSet1.DefaultView %>'> </asp:DropDownList>
      年

      <asp:DropDownList ID="DropDownList2" runat="server">
        <asp:ListItem value="0">---不限---</asp:ListItem>
        <asp:ListItem value="">1</asp:ListItem>
        <asp:ListItem value="2">2</asp:ListItem>
        <asp:ListItem value="3">3</asp:ListItem>
      
</asp:DropDownList>
....

<script language="vb" runat="server">

    Sub click(sender as object,e as eventargs)
        Dim MyConnection as OLEDBConnection
        Dim MyCommand,MyCommand2 as OleDbCommand
        Dim s,sexs,ages,nameID,daName As String
        Dim i As Integer
        daName = TextBox1.Text
        MyConnection = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("..\source\dabo.mdb"))
        MyCommand=new OleDbCommand("select daName from daInfo where daName='"+TextBox1.text+"'",MyConnection)
        MyConnection.open()
   
            If RadioButton1.checked Then   
                sexs="男"
            Else If RadioButton2.checked Then   
                sexs="女"
            End If
            
            If (Page.IsPostBack) Then
            
            DropDownList2.Items(i).Selected Then
                 ages = DropDownList2.Items(i).Text
                    
            Else
                ages = "2ee3"
            End If
            
2 回复
#2
cnfarer2011-11-18 21:22
DropDownList2.SelectedValue
#3
白色艾艾2011-12-08 16:12
C#中的DropDownList控件如何获取它的文本值?
string a=DropDownList1.SelectedItem.Text;//这是获取选中的文本值
string a=DropDownList1.SelectedValue;//获取DropDownList中你设定的Value值
1