Avatar of mconti41
mconti41

asked on 

Maintain Header Item in Drop Down List Box

When I do a data source request my default Item --Please chose Coverage Group-- disappears. All db retrieved items are in DDLB. GHow can I maintain default item above.
.NET ProgrammingVisual Basic.NETWeb Development Software

Avatar of undefined
Last Comment
abel
Avatar of abel
abel
Flag of Netherlands image

You will have to add it manually after the data binding of the control.
Avatar of mconti41
mconti41

ASKER

How would I make sure it was first in the list and what event should I use?
Avatar of abel
abel
Flag of Netherlands image

So, suppose you are talking of a listbox here, named myListbox, you could do the following, which adds the item and selects it:

myListbox.Items.Add(New ListItem("--Please chose Coverage Group--", ""))
myListbox.SelectedValue = ""

Open in new window

Avatar of mconti41
mconti41

ASKER

I appreciate your response but what event would be best...
Avatar of abel
abel
Flag of Netherlands image

My apologies for the post above: it was posted before I saw your new comment....

> How would I make sure it was first in the list and what event should I use?
You shouldn't use any event, you can simply put it after your DataBind() statement, like this:



myListbox.Items.Clear()
myListbox.Items.Add(New ListItem("<geen>", "none"))
myListbox.AppendDataBoundItems = True
myListbox.DataSource = mydatasource
myListbox.DataBind()

Open in new window

Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

You can try something like this:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   If Not Page.IsPostBack Then
         YourDropDown.Items.Insert(0, " --Please chose Coverage Group-- ")
   End If
End Sub
Avatar of abel
abel
Flag of Netherlands image

The property "AppendDataBoundItems" makes sure that the original content is not lost and stays on top (so you do not have to reorganize it). The line with "geen" (sorry, that's Dutch, forgot to replace it with your sentence above) is the extra line which should be on top.

I am not sure whether you use the DataBind statement or not, but if you do, this is the way to go.
Avatar of mconti41
mconti41

ASKER

jpaulino thanks for staying with this:

Here is my current .aspx code:


             
               
             
       
       
           
           

I used the not post back code you suggested but it still did not insert the header row.
ASKER CERTIFIED SOLUTION
Avatar of abel
abel
Flag of Netherlands image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of abel
abel
Flag of Netherlands image

ataSourceID >> DataSourceID
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo