Solved

dropdownlist items doubling up

Posted on 2007-04-02
5
709 Views
Last Modified: 2011-10-03
Hi
I have a number of dropdownlists that are bound to the same gridview datasource.
I need to have a blank row at the top of each.
So my dropdownlist settings look like this. (Each list is identical except for the ID):

<asp:DropDownList
            ID="DDLServiceType1"
            runat="server"
            EnableViewState = "True"
            AppendDataBoundItems="True"
            DataSourceID="ServiceType"
            DataValueField="ServiceID"
            DataTextField="ServiceName"
            AutoPostBack="True"
            onselectedindexchanged="UpdateProviderList">
            <asp:ListItem Value=""></asp:ListItem>
    </asp:DropDownList>

This works perfectly for me except on postback the dropdownlist doubles up with entries. If I take out the AppendDataBoundItems the problem is fixed but I then do not get a blank row. If I clear the items in my sub I lose my selected item. Can someone please let me know how I can have a dropdownlist that allows me a blank row at the top, retains its selection on postback and does not double up its items on postback
thx heaps
Verdy
0
Comment
Question by:verdante
  • 3
  • 2
5 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
Comment Utility
In your page load

If not Me.IsPostback Then
' load combo box here
End If
0
 

Author Comment

by:verdante
Comment Utility
Thx Chaosian
In this scenario do I programatically assign the datasource to each dropdwonlist as opposed to specifying a static datasourceid in each dropdownlist definition?
cheers
Verdy
0
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 500 total points
Comment Utility
I usually retrieve the data, then operate programatically on the DataTable to insert the new row.

' Get the data and put it into the DataTable dt
Dim row as DataRow = dt.NewRow
dt("ID_column_name") = 0
dt("description_column_name") = string.empty
dt.rows.insertat(row, 0)

Of course, I generally don't use the drag-and-drop data sources -- partly beacuse of limitations like this one.
0
 

Author Comment

by:verdante
Comment Utility
Chaosian
Thank you very much for your response. It's enormously helpful for those with limited experience like me to gain such valuable advice.
cheers
Verdy
0
 
LVL 24

Expert Comment

by:Jeff Certain
Comment Utility
My pleasure -- always glad to help.  We were all there once....
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now