Data is not getting updated in dropdownlist using data set.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Parita Pandya
    New Member
    • Sep 2013
    • 3

    Data is not getting updated in dropdownlist using data set.

    Data is not getting updated in dropdownlist using data set:

    Code:
     protected void SpecificationNameDropDownList_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (SpecificationNameDropDownList.SelectedItem.Text != null)
                {
                    SpecificationValueLabel.Visible = true;
                    SpecificationValueDropDownList.Visible = true;
                    SqlConnection sqlConnection = new SqlConnection(this.connectionString);
                    int specificationcode = Convert.ToInt32(SpecificationNameDropDownList.SelectedValue);
                    DataSet specificationNameDS = new DataSet();
                    string getSpecificationValue = "SELECT S.SpecificationValueCode,S.SpecificationValue FROM SpecificationValueMaster S,SpecificationMaster SV WHERE SV.SpecificationCode='" + specificationcode + "' AND SV.SpecificationCode = S.SpecificationCode";
                    SqlDataAdapter SpecificationValueSDA = new SqlDataAdapter(getSpecificationValue, sqlConnection);
                    SpecificationValueSDA.Fill(specificationNameDS, "SpecificationValueMaster");
                    SpecificationValueDropDownList.DataSource = specificationNameDS;
                    SpecificationValueDropDownList.DataTextField = "SpecificationValue";
                    SpecificationValueDropDownList.DataValueField = "SpecificationValueCode";
                    SpecificationValueDropDownList.DataBind();
                    SpecificationValueDropDownList.Items.Insert(0, new ListItem("Select Value", ""));
                }
                else
                {
                    SpecificationValueLabel.Visible = false;
                    SpecificationValueDropDownList.Visible = false;
                }
            }
    Last edited by Frinavale; Dec 2 '13, 03:49 PM. Reason: Added the problem stated in the title of the thread to the body of the thread so that the posted code has context.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    You are populating the DropDownList in the following case:
    Code:
    if (SpecificationNameDropDownList.DataSource != null)
    Are you sure that is the case that you want?

    Would it make more sense to populate the list in the following case instead?
    Code:
    if (SpecificationNameDropDownList.SelectedItem.Text == null)
    Or how about this case:
    Code:
    if (SpecificationNameDropDownList.DataSource == null)
    -Frinny

    Comment

    Working...