Solved

dropdownlist items doubling up

Posted on 2007-04-02
5
715 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

867 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

13 Experts available now in Live!

Get 1:1 Help Now