Solved

dropdownlist items doubling up

Posted on 2007-04-02
5
724 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 18840187
In your page load

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

Author Comment

by:verdante
ID: 18840247
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
ID: 18840264
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
ID: 18840301
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
ID: 18840305
My pleasure -- always glad to help.  We were all there once....
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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