Hi All
I have droplistlist populated from database.When i add records everthing is ok with the dropdownlist: but when i edit records it shows duplicate values like
High
Medium
Low
Medium
how can i romove duplicate values?

hi,

may be your dropdownlist values are concatenating with previous values.check that once.did u assign appenddataitems to true for the droddownlist.i would like to see u r code to help u more.

Dim dt As Data.DataTable = objlist.GetPriorityList()
Dim dr As Data.DataRow = dt.NewRow
dr.Item("PriorityID") = 0
dr.Item("Priority") = "--Select--"
dt.Rows.Add(dr)
ddlPriority.DataSource = dt
ddlPriority.DataTextField = "Priority"
ddlPriority.DataValueField = "PriorityID"
ddlPriority.DataBind()
ddlPriority.SelectedValue = 0
When i add records ddlpriority is properly populated.
But when edit sub is called it shows values like
low
medium
high
medium
excluding select.
here is code of edit subroutine
ddlPriority.SelectedItem.Text = dr("Priority")

one thing i forget is that values low medium high r coming from database

HI,

Try like this.what u are doing is you are assinging the values of edited datareader values to the already selected dropdownlist.so you are getting that error.

ddlist.Items.FindByText(dr("Priority") ).Selected = true;

if the values coming from db having duplicates then use distinct keyword.otheerwise clear the dropdown items every time before adding like
in c#

ddlCountry.Items.Clear();

hi greeny_1984
ddlist.Items.FindByText(dr("Priority") ).Selected = true
gaves error "Cannot have multiple items selected in a DropDownList. "
But when i add "'ddlPriority.ClearSelection()" before urs line of code it really works.
Thank u greeny_1984 and srikathkadem

hi,

so mark the thread as solved

ddlist.Items.FindByText(dr("Priority") ).Selected = true
gaves error "Cannot have multiple items selected in a DropDownList. "
But when i add "'ddlPriority.ClearSelection()"

this really helped me a lot.
thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.