I have 2 dropdownlists in a detailsview. One dropdownlist filters the others listitems.
My issue is that I can not figure out how to insert a -1 or 0 value for the top menu text.
Here is the html:
Code:
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DefaultMode="Insert">
<Fields>
<asp:TemplateField HeaderText="Operating System" SortExpression="OperatingSystem" HeaderStyle-Width="225">
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" DataSourceID="SqlDataSource2" DataTextField="OperatingSystem" DataValueField="Id" AppendDataBoundItems="true" Width="210px">
<asp:ListItem Value="-1">-- Select Operating System --</asp:ListItem>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("OperatingSystem") %>'></asp:Label>
</ItemTemplate>
<asp:CommandField ShowInsertButton="False" />
</Fields>
</asp:DetailsView>
You can see here the reloading of the second dropdownlist:
Code:
protected void dvDropDownList2Model_DataBound(object sender, EventArgs e)
{
DropDownList DropDownList2Model = (DropDownList)sender;
DetailsView DetailsView1 = (DetailsView)DropDownList2Model.NamingContainer;
if (DetailsView1.DataItem != null)
{
string strModel = ((DataRowView)DetailsView1.DataItem)["Id2"] as string;
ListItem lm = DropDownList2Model.Items.FindByValue(strModel);
//DropDownList2Model.Items.Add(new ListItem("Select Model", "-1"));
if (lm != null) lm.Selected = true;
}
I have tried many approaches to insert/add the item (this is one of MANY):
Code:
DropDownList2Model.Items.Insert(0, "<-- Select -->");
How can I get this into the dropdownlist view?
