0

Dropdownlist it binding only First value.If i selected second value also its binding first value For example my deopdownlist List1,List2,List3 3 values are there ,I selected List3 but it bind List1

here is my code someone help me for this.

private void BindObligationType()
    {
        try
        {
            DataTable aDtblOblType = objObligation.GetObligationsType();

            if (aDtblOblType != null)
            {
                DataRow dataRow = aDtblOblType.NewRow();
                dataRow["Title"] = Convert.ToString(objutility.GetResourceString("Obligation_Type_Validation"));
                dataRow["ContentTypeName"] = "None";
                aDtblOblType.Rows.InsertAt(dataRow, 0);

                ddlObligationType.DataSource = aDtblOblType;
               //ddlObligationType.DataValueField = "ContentTypeName";
                ddlObligationType.DataValueField = "Title";
                ddlObligationType.DataTextField = "Title";
                ddlObligationType.DataBind();
            }
}

}

  • you have some part missing in code.the code is not properly copy pasted. – Codec May 4 '16 at 7:29
  • Make sure you first call BindObligationType() before setting the value to dropdown – Amal Hashim May 4 '16 at 7:37
  • HI i edited my code now it was working.I gave the same value of "title" ddlObligationType.DataValueField and ddlObligationType.DataTextField This is correct or wrong. – Elina May 4 '16 at 7:43
  • After i changed ddlObligationType.DataValueField = "Title"; now Dropdown functionality is working but what i did is correct way or wrong please someone suggest me – Elina May 4 '16 at 8:07
  • DataTextField is what the user can see. DataValueField is what you can use for identify which one is selected from DropDownList. Like: <asp:ListItem id="opt_Audit" value="1" selected="False">One</asp:ListItem> Here DataTextField = One DataValueField = 1 – Thirusanguraja Venkatesan May 4 '16 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.