Inserting a new item in a dropdownlist which was binded with an ObjectDataSource

H

Hugo Flores

I bound the items of a DropDownList with an ObjectDataSource, but I
also want to add a new item at top with an option that would say All,
and an emtpy value.

I tried this
Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
ddl.Items.Insert(0, New ListItem("All", ""))
End Sub

But that doesn't work

This is my .aspx code

<asp:DropDownList ID="ddl" runat="server"
DataSourceID="ObjectDataSource1" DataTextField="name"
DataValueField="id">
</asp:DropDownList>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetAllEntities"
TypeName="Entities"></asp:ObjectDataSource>

I'm pretty sure, there is a way, I just don't know how
Thanks
 
T

Teemu Keiski

Specify the 'All' item declaratively on aspx and set AppendDataBoundItems on
the DropDownList to true.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top