Alex Rivera | Logout

DropDownList AppendDataBoundItems (first item to be blank and no duplicates)

Asked 2009-04-08T15:34:27.497
37

I have a DropDownList inside an UpdatePanel that is populated on postback from a SqlDataSource. It has a parameter which is another control. I sometimes need multiple postbacks, but what happens is that each time the update panel refreshes, items are added to the DropDownList. So the DropDownList ends up having data that is incorrect, or repeated data.

I have the AppendDataBoundItems property set to true because I need the first item to be blank.

How can I overcome this problem? Is there another way to have a blank first item?

(This DropDownList is in an ASP.NET 2.0 web app, and codebehind is in C#)

Edit
Report

1 Answer

0
<asp:DropDownList ID="DropDownList1" AppendDataBoundItems="true" runat="server"
  DataSourceID="SqlDataSource1" DataTextField="state" DataValueField="state">
    <asp:ListItem Text="(Select a State)" Value="" />
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
  ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>"
  SelectCommand="SELECT DISTINCT [state] FROM [authors]">
</asp:SqlDataSource>
answered 2010-04-05T17:49:29.043

Your Answer