M
mark4asp
The first intem in a DropDownList is vanishing!
My code to load a DropDownList is shown below. Yet when I load the
page after a postback there is no zeroth item present.
lstManager.Items.Clear();
lstManager.DataSource = _dsData.Tables["manager"].DefaultView;
lstManager.DataValueField = "ManagerID";
lstManager.DataTextField = "Name";
lstManager.DataBind();
lstManager.Items.Insert(0, new ListItem("none", "0"));
There's nothing special about the control definition:
<aspropDownList ID="lstManager" runat="server" Height="20px"
Width="250px" />
What's going on here?
This was the old code I replaced. Why does the old code (below) work
and why is my new code (above) broke?
lstManager.Items.Clear();
ListItem li = new ListItem("none","0");
lstManager.Items.Add(li);
foreach (DataRow drManager in _dsData.Tables["manager"].Rows)
{
ListItem liManager = new ListItem((string)drManager["Name"],
((int)drManager["ManagerID"]).ToString());
lstManager.Items.Add(liManager);
}
My code to load a DropDownList is shown below. Yet when I load the
page after a postback there is no zeroth item present.
lstManager.Items.Clear();
lstManager.DataSource = _dsData.Tables["manager"].DefaultView;
lstManager.DataValueField = "ManagerID";
lstManager.DataTextField = "Name";
lstManager.DataBind();
lstManager.Items.Insert(0, new ListItem("none", "0"));
There's nothing special about the control definition:
<aspropDownList ID="lstManager" runat="server" Height="20px"
Width="250px" />
What's going on here?
This was the old code I replaced. Why does the old code (below) work
and why is my new code (above) broke?
lstManager.Items.Clear();
ListItem li = new ListItem("none","0");
lstManager.Items.Add(li);
foreach (DataRow drManager in _dsData.Tables["manager"].Rows)
{
ListItem liManager = new ListItem((string)drManager["Name"],
((int)drManager["ManagerID"]).ToString());
lstManager.Items.Add(liManager);
}