Solved

dropdownlist items doubling up

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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.…
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…
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 …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

805 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