Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

dropdownlist items doubling up

Posted on 2007-04-02
5
Medium Priority
?
728 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 2000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

705 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