开发者

SQL DropDownList - ListItem inserts [closed]

开发者 https://www.devze.com 2023-04-06 12:27 出处:网络
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
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

精彩评论

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