You must Sign In to post a response.
  • Category: ASP.NET

    Dropdownlist selected value is not saved in the database

    In run mode as follows

    Name textbox1

    Designation Courseofficer (Dropdownlist)


    in the designation column three values are there in the dropdownlist

    When user type the name ram in textbox1 and select the designation from the dropdownlist.

    Suppose i am selecting the Courseofficer from the dropdownlist and click Save button records are saved.

    but i am selecting the courseofficer from the dropdownlist only. But in database
    last value Director is saved in the database.

    Save button code as follows

    Sql = "insert into Designations values('" + txt_name.Text + "','" + ddldesg.SelectedValue.ToString() + "')";
    LblErr.Text = "Record Inserted Successfully";

    In database records as follows

    ID Name Designations
    1 Ram Director

    please help me what is the problem in my above code.
  • #761483

    Can you share your code then only we have solve fast your issue.

    Debugging this line check your insert query.


    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761486

    you can go through Below link

    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761497
    Hello Rao,

    Try this code :

    protected void btnSave_Click(object sender, EventArgs e)
    for (int i = 0; i < DropDownList1.Items.Count; i++)
    cmd = new SqlCommand("INSERT INTO Student_Designations VALUES ('" + DropDownList1.Items[i].Text + "')", con);
    Response.Write("<script>alert('" + Server.HtmlEncode("Records saved successfully") + "')</script>");
    catch (Exception ex)

    Hope this will help you.

    See the attached image, it's an output of this code.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #761519
    Hai Rao,
    It seems somewhere your dropdown is doing postback and getting the last value selected and saved.
    You need to disable the postback for the dropdown so that the page should not be postback during the selection from the dropdown.
    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • Sign In to post your comments