有个DropDownList控件,里面是“男”“女”两个选项,如果我选择了“男”,则数据库里添加的是1,如果选择了“女”,则数据库里添加的是2,怎样做啊?
反之呢?比如数据库里查询出来的是1或2,要怎样在DropDownList里显示“男”或“女”呢??

解决方案 »

  1.   

    2个item的value分别设置成1和2
    然后设置selectvalue=要选择的值
    代码嘛就不贴出来了
      

  2.   

    页面上这样
    <asp:DropDownList ID="ddlSex" runat="server">
        <asp:ListItem Value="0" Selected="True">--请选择--</asp:ListItem>
        <asp:ListItem Value="1">男</asp:ListItem>
        <asp:ListItem Value="2">女</asp:ListItem>                    
    </asp:DropDownList>保存的时候保存this.ddlSex.SelectedValue
    显示的时候this.ddlSex.SelectedValue=查出来的值
      

  3.   

    DropDownList1.SelectedValue 取value   DropDownList1.SelectedItem 取text
      

  4.   

      忘了 后边取的   先页面
    <asp:DropDownList ID="ddlSex" runat="server"> 
        <asp:ListItem Value="0" Selected="True">--请选择-- </asp:ListItem> 
        <asp:ListItem Value="1">男 </asp:ListItem> 
        <asp:ListItem Value="2">女 </asp:ListItem>                    
    </asp:DropDownList> 
       直接将数据库里边查出来的那个值在后边加一句DropDownList1.SelectedValue=1  就OK了
      
      

  5.   

    手动添加
    <asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem Value="1">男</asp:ListItem>
                <asp:ListItem Value="2">女</asp:ListItem>
            </asp:DropDownList>再通过下代码获取
    int sexid=DropDownList1.SelectedValue;
      

  6.   

    ]
    <asp:DropDownList ID="DropDownList1" runat="server"> 
        <asp:ListItem Value="0" Selected="True">--请选择-- </asp:ListItem> 
        <asp:ListItem Value="1">男 </asp:ListItem> 
        <asp:ListItem Value="2">女 </asp:ListItem>                    
    </asp:DropDownList> 
    存:DropDownList1.SelectedValue 存入数据库
    取:DropDownList1.SelectedValue = 数据库取出的值
      

  7.   

    有value和text属性嘛
    value=1 text='男'
    value=2 text='女'
    显示的时候ui界面上显示的是text
    存储或者选择都是按value来处理不就可以啦