jimbona27
asked on
dropdownlist listitem arraylist
hi there,
I have an arraylist that binds to a dropdownlist.
My problem is that I use the data from the arraylist more than once for different things...
when I use the data for the dropdownlist I need to prefix the options with a Please Select as the first entry within the arraylist.
I have tried the following,
arraylist test = new
while (reader.Read())
test.Add(reader["name"]));
this gets the data for the dropdownlist..
as the dropdownlist needs the first option to be please select I have used a listitem within the markup template, shown below. this doesnt render? i guess the databind overwrites this..??
<asp:DropDownList ID="test" runat="server">
<asp:ListItem>select</asp: ListItem>
</asp:DropDownList>
any suggestions how I can prefix the arraylist when I use the data for the dropdownlist with a listitem? thanks
I have an arraylist that binds to a dropdownlist.
My problem is that I use the data from the arraylist more than once for different things...
when I use the data for the dropdownlist I need to prefix the options with a Please Select as the first entry within the arraylist.
I have tried the following,
arraylist test = new
while (reader.Read())
test.Add(reader["name"]));
this gets the data for the dropdownlist..
as the dropdownlist needs the first option to be please select I have used a listitem within the markup template, shown below. this doesnt render? i guess the databind overwrites this..??
<asp:DropDownList ID="test" runat="server">
<asp:ListItem>select</asp:
</asp:DropDownList>
any suggestions how I can prefix the arraylist when I use the data for the dropdownlist with a listitem? thanks
Change you asp page to use the AppendDataBoundItems property:
<asp:DropDownList ID="test" runat="server" AppendDataBoundItems='true '>
<asp:ListItem>select</asp: ListItem>
</asp:DropDownList>
<asp:DropDownList ID="test" runat="server" AppendDataBoundItems='true
<asp:ListItem>select</asp:
</asp:DropDownList>
ASKER
thanks Surajguptha although this doesnt work. it complains about the insertat does not exist for listitemcollection?
thanks MogalManic, this works great. can you confirm that this is just adding the listitem before the binding event? is that it? and can you control this, can you add after the bind?
thanks, would like to know both answers, many thanks
thanks MogalManic, this works great. can you confirm that this is just adding the listitem before the binding event? is that it? and can you control this, can you add after the bind?
thanks, would like to know both answers, many thanks
DropDownList1.Items.Insert (0,SelectL istItem)
where 0 is the index
where 0 is the index
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i'll be able to provide feedback after wednesday as my computer died and my new laptop :) is arriving then..
sorry for the wait..
sorry for the wait..
ASKER
thanks
ASKER
Surajguptha I have tried the following although I get an error that the Insertat does not exist within the definition??
test.DataSource = testoptions;
test.DataBind();
test.Insertat(0, "test");
test.DataSource = testoptions;
test.DataBind();
test.Insertat(0, "test");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It is different for web and windows control. Yes thats right. Insert(0,"Test") is what i meant :)
ASKER
ok many thanks
This selectListItem is the ListItem witht he text "[Select One]"