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:
<asp:DropDownList 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);
} 2 1398
I had this one a while back; turns out I was using simple properties
on a Master Page that required a DataBind() call to bind them. When
it was called, it was also rebinding the content page, which loses the
manually added items.
I recall this issue also happened with an ASCX file on the page, or if
you call a generic DataBind() any time after the addition of
ListItems, etc.
Dunc http://www.fluidfoundation.com
On 1 Jun, 15:24, mark4asp <mark4...@gmail.comwrote:
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:
<asp:DropDownList 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);
}
On 1 Jun, 16:30, Dunc <duncan.we...@gmail.comwrote:
I had this one a while back; turns out I was using simple properties
on a Master Page that required a DataBind() call to bind them. When
it was called, it was also rebinding the content page, which loses the
manually added items.
I recall this issue also happened with an ASCX file on the page, or if
you call a generic DataBind() any time after the addition of
ListItems, etc.
Dunchttp://www.fluidfoundation.com
On 1 Jun, 15:24, mark4asp <mark4...@gmail.comwrote:
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:
<asp:DropDownList 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);
}- Hide quoted text -
- Show quoted text -
Thanks Dunc, for sharing that with me - that scenario you described
sounds very like mine. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: honeybee |
last post by:
How to get the index of a selected intem in the listbox?
|
by: Greg |
last post by:
There is a repeating issue of controls vanishing from a form in the Dev
environment which is starting to get annoying.
What happens is that I will have a form open in the IDE. The form will have...
|
by: Andrew Ducker |
last post by:
My unhandled exceptions seem to just vanish. If I put the line:
int x = int.Parse("XXX");
in (which generates an exception, obviously) then the code that's
executing just vanishes, leaving me...
|
by: Micheal |
last post by:
I have an ASP.NET website using C# that has a Web Control DropDownList. The
DropDownList is filled by a database call to SQL Server. The problem is
that when I click to change what is selected...
|
by: Harry |
last post by:
Hi,
Just seeing if anyone can help me with a problem I am having with drop
down lists.
- I have a asp:dropdownlist that gets its values from a database.
- The user then selects a value then...
|
by: Michael |
last post by:
After trying to load my java applet from <OBJECT> tag
(rather than <APPLET> tag), it renders fine, except when
you click between the DESIGN view then back to HTML view,
the <PARAM NAME="ARCHIVE"...
|
by: danc |
last post by:
I have a datagrid with a checkbox and dropdown list in each row. Both set
AutoPostBack to true and ItemCommand and OnSelectedIndexChanged events for
these controls works fine when DataGrid is not...
|
by: Evan M. |
last post by:
Here's my GridView and my SqlDataSource
<asp:GridView ID="ContactHistoryGrid" runat="server"
AutoGenerateColumns="False" DataSourceID="ContactHistoryDS"
DataKeyNames="JobHistoryID"...
|
by: TC |
last post by:
I've used Access for many years. Several times, I've encountered a bug
which I refer to as the "Vanishing Joins" bug. When it happens, joins
vanish randomly from queries. More specifically, all...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |