Home All Groups Group Topic Archive Search About

Insert item into dropdown

Author
7 Jul 2006 7:02 PM
Chris
I am trying to insert an item into a dropdown which is bound to an
sqldatasource. Nothing happens when I place the following code in page load
and render event. Is the datasource overriding my insert or am I doing
something wrong

Dim lstitemcompany As New ListItem

lstitemcompany.Text = "Select a company"

lstitemcompany.Value = ""

drpCompanies.Items.Insert(0, lstitemcompany)

Author
7 Jul 2006 7:09 PM
neilmcguigan
do the insert in the DataBound event handler:

    protected void DropDownList1_DataBound(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        ddl.Items.Insert(0, new ListItem("text", "value"));
    }


Chris wrote:
Show quoteHide quote
> I am trying to insert an item into a dropdown which is bound to an
> sqldatasource. Nothing happens when I place the following code in page load
> and render event. Is the datasource overriding my insert or am I doing
> something wrong
>
> Dim lstitemcompany As New ListItem
>
> lstitemcompany.Text = "Select a company"
>
> lstitemcompany.Value = ""
>
> drpCompanies.Items.Insert(0, lstitemcompany)



Post Thread options