SQL DropDownList - ListItem插入

时间:2011-09-21 01:37:54

标签: asp.net sql database drop-down-menu

我有dropdownlist(DDL)供用户在两个值之间进行选择,以通过代码隐藏/存储过程文件插入到数据库中。除了我尝试在'if else'语句中添加DDL之外,我的所有表单都适用于DDL方法。当我这样做时,表单就像插入信息一样正常,但不会将值插入数据库。

ASPX代码

<tr><td>Active: </td><td>
  <asp:DropDownList ID="DropDownListActive" runat="server" AutoPostBack="True" 
    Width="128px" AppendDataBoundItems="true" Height="22px">
    <asp:ListItem>Select</asp:ListItem>
    <asp:ListItem>Yes</asp:ListItem>
    <asp:ListItem>No</asp:ListItem>
  </asp:DropDownList>
  <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</td></tr>

代码隐藏:

if (DropDownListActive.SelectedValue == "Select")
{
    Label1.Text = "Please select Yes or No.";
    return;
}
else
{
    cmd.Parameters.Add(new SqlParameter("@Active", SqlDbType.VarChar, 3));
    cmd.Parameters["@Active"].Value = DropDownListActive.SelectedValue;
}

0 个答案:

没有答案
相关问题