binding data to a dropdownlist Question

C

chongo

hi,

I'm a newbie to asp.net.

I have a dropdrown list

<asp:dropdownlist id="department" runat="server"
DataValueField="departmentid" DataTextField="departmentname">
<asp:ListItem Value="0">No Department</asp:ListItem>
</asp:dropdownlist>

The problem I'm having is that when I bind a dataset to the
dropdownlist, it erases the "<asp:ListItem Value="0">No
Department</asp:ListItem>".

Is there a way to bind the data to the dropdownlist without erasing
the listItems.

-dan
 
H

hb

chongo said:
hi,

I'm a newbie to asp.net.

I have a dropdrown list

<asp:dropdownlist id="department" runat="server"
DataValueField="departmentid" DataTextField="departmentname">
<asp:ListItem Value="0">No Department</asp:ListItem>
</asp:dropdownlist>

The problem I'm having is that when I bind a dataset to the
dropdownlist, it erases the "<asp:ListItem Value="0">No
Department</asp:ListItem>".

Is there a way to bind the data to the dropdownlist without erasing
the listItems.


Remove the <asp:ListItem> from the HTML.

In your code behind, after the DataBind to the dropdownlist, add something
like this:

dropDownList.Items.Insert( 0, "No Department" );
 

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

Top