locked
dropdown RRS feed

  • Question

  • User-1499457942 posted

    Hi

      In the below code what is the correct way

    cmd.Parameters.AddWithValue("@Category", SqlDbType.VarChar).Value = ddl_Category.SelectedItem.Value;

    cmd.Parameters.AddWithValue("@Category", SqlDbType.VarChar).Value = ddl_Category.SelectedValue;

    Thanks

    Sunday, October 14, 2018 5:51 AM

Answers

  • User-369506445 posted

    hi

    SelectedValue returns the same value <g class="gr_ gr_41 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="41" data-gr-id="41">as </g>SelectedItem.Value<g class="gr_ gr_41 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Style multiReplace" id="41" data-gr-id="41">.</g>

    SelectedItem.Value <g class="gr_ gr_40 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="40" data-gr-id="40">and </g>SelectedItem.Text<g class="gr_ gr_40 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Style multiReplace" id="40" data-gr-id="40"> might</g> have different values and the performance is not a factor here, only the meanings of these properties matters.

    <asp:DropDownList runat="server" ID="ddlUserTypes">
        <asp:ListItem Text="Admins" Value="1" Selected="true" />
        <asp:ListItem Text="Users" Value="2"/>
    </asp:DropDownList>

    Here, ddlUserTypes.SelectedItem.Value == ddlUserTypes.SelectedValue and both would return the value "1".

    ddlUserTypes.SelectedItem.Text would return "Admins", which is different from ddlUserTypes.SelectedValue

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 14, 2018 6:00 AM