locked
DropDown List RRS feed

  • Question

  • User-1499457942 posted

    Hi

     I have below code . I want to save dropdown value in Database . DataValue Field DataType is int

    ddl_Category.DataTextField = "Description";
    ddl_Category.DataValueField = "No";

    Thanks

    Friday, August 24, 2018 5:17 PM

Answers

  • User2103319870 posted

    I want to save dropdown value in Database . DataValue Field DataType is int

    You can use Dropdownlist SelectedItem property to get the selected value from dropdownlist

    DropDownList1.SelectedItem.Value

    To save the value in database, you just need to add the value to command property like below

    //Add the value from dropdownlist to parameter
    cmd.Parameters.AddWithValue("@YourParameter", Convert.ToInt32(DropDownList1.SelectedItem.Value));
    //Your code to save value in database

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 24, 2018 5:45 PM

All replies

  • User2103319870 posted

    I want to save dropdown value in Database . DataValue Field DataType is int

    You can use Dropdownlist SelectedItem property to get the selected value from dropdownlist

    DropDownList1.SelectedItem.Value

    To save the value in database, you just need to add the value to command property like below

    //Add the value from dropdownlist to parameter
    cmd.Parameters.AddWithValue("@YourParameter", Convert.ToInt32(DropDownList1.SelectedItem.Value));
    //Your code to save value in database

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 24, 2018 5:45 PM
  • User475983607 posted

     I have below code . I want to save dropdown value in Database . DataValue Field DataType is int

    ddl_Category.DataTextField = "Description";
    ddl_Category.DataValueField = "No";

    I'm a bit confused... Clearly in other posts you have saved data in a table.  Why are you having an issue at this time?  

    Is the problem that the field named "No" is not an integer?  Are you receiving an error?  Can you post the code that is causing the problem?  Lastly, and most importantly please describe in detail the troubleshooting steps you have performed up to this point.

    Friday, August 24, 2018 5:47 PM