开发者

SQL DropDownList - ListItem inserts [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.

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 question

I 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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜