adding a blank entry into a combo box

C

Craig G

i use the following to populate a combo in a datagrid but was wondering how
i would add a blank entry to the top of the combo so that on first load it
has no value selected?

<asp:DropDownList id=cboIntensityAdd runat="server" Width="149px"
CssClass="yarGridCombo" DataValueField="CODE" DataTextField="PAININTENSITY"
DataSource="<%# FillPainIntensityCombo() %>"></asp:DropDownList>

FillPainIntensityCombo simply selects all records from a table using an
oracle stored proc.

Cheers,
Craig
 
E

Eliyahu Goldin

After populating the table from the database, add an empty record in the
code.

Eliyahu
 
K

Kikoz

First of all, I'd really recommend using code-behind classes.

You can't add new item to ddl by setting it's attributes. In your code, type
the following:

ListItem li = new ListItem("Text To Be Displayed","Value");
cboIntensityAdd.Items.Add(li);
 
G

Guest

other responses suggest the right path, but are not your specific solution
which wants an empty item at the top (so that the client can select any OTHER
item successfully, otherwise the initially "selected" item cannot be
immediately re-selected--I think that is your issue!)

1. solution must be in code, either on page or code-behind, as others point
out.
2. after databinding has occurred, you simply insert (not add) an empty
ListItem at the front of the list:

cboIntensityAdd.Insert(0, new ListItem);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top