SQL DropDownList - ListItem inserts [closed]
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this questionI have a dropdownlist
(DDL) for a user to select between two values to insert into the database via codebehind/stored procedure file. All my forms work well with the DDL method except when I try to add the DDL in an 'if else'
statement开发者_如何转开发. When I do this the form acts normal as if the information was inserted but doesn't insert values into the database.
ASPX CODE
<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>
CODE-BEHIND:
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;
}
精彩评论