T
taa
I'm trying to fill a dropdownlist using the datasource and bind,
however the item I added in advance manually disabpears when the data
is bound. Is there a way to keep the item in the control?
I'm using the code bellow, but I would like to use the outcommented
code instead of the foreach-loop. Ideas?
protected void FillLoadBox(object sender, EventArgs e)
{
DropDownList1.Items.Clear();
DropDownList1.Items.Add(new ListItem("New program...", "-1"));
var UserPrograms = from sp in context.SimplePrograms
select new
ListItem(sp.Name,sp.SimpleProgramId.ToString());
//DropDownList1.DataSource = UserPrograms;
//DropDownList1.DataBind();
foreach (var program in UserPrograms)
{
DropDownList1.Items.Add(new ListItem(program.Name,
program.Id.ToString()));
}
}
however the item I added in advance manually disabpears when the data
is bound. Is there a way to keep the item in the control?
I'm using the code bellow, but I would like to use the outcommented
code instead of the foreach-loop. Ideas?
protected void FillLoadBox(object sender, EventArgs e)
{
DropDownList1.Items.Clear();
DropDownList1.Items.Add(new ListItem("New program...", "-1"));
var UserPrograms = from sp in context.SimplePrograms
select new
ListItem(sp.Name,sp.SimpleProgramId.ToString());
//DropDownList1.DataSource = UserPrograms;
//DropDownList1.DataBind();
foreach (var program in UserPrograms)
{
DropDownList1.Items.Add(new ListItem(program.Name,
program.Id.ToString()));
}
}