473,396 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can't add items to dropdownlist

Hi again,
I really hope that there is a simple solution to this one, cause I'm having
simular things happening to other controls on this usercontrol. I have the
following control:
<asp:DropDownList ID="cmbOptions" runat="server" Width="195px">
<asp:ListItem Text="Search by PO ID" Value=0 Selected="True"
/>
<asp:ListItem Text="Search by Field" Value=1 />
<asp:ListItem Text="Search between dates" Value=2 />
<asp:ListItem Text="Search Most recent Num days" Value=3 />
</asp:DropDownList><br />
This would be the default list that all user would see. If a Adin logged in,
I wanted to add a few more items to the list using the follwoing code in the
usercontrol:
cmbOptions.Items.Add(New ListItem("Search by UserId", "4"))
cmbOptions.Items.Add(New ListItem("Awaiting Approval", "5"))
If I check the count before each one, and then check after, the count does
increment, but after the page re-renders, the two exrta items are not listed.
Am I missing something. This is driving me crazy. BTY, EnableViewState is
enabled for the dropdownlist control if that makes a difference in this case.
Thanks for any suggestions.
Michael

Apr 26 '06 #1
2 2263
I think you've run into the classic misunderstanding that when a page posts
back, you need to "reconstitute" any custom items you've added to your
control in the interim.

So for example, in your page_load you might do something like

if( User.IsInRole("Admins")
{
AddBackMyExtraOptions();
}

Hoipe that helps.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Michael" wrote:
Hi again,
I really hope that there is a simple solution to this one, cause I'm having
simular things happening to other controls on this usercontrol. I have the
following control:
<asp:DropDownList ID="cmbOptions" runat="server" Width="195px">
<asp:ListItem Text="Search by PO ID" Value=0 Selected="True"
/>
<asp:ListItem Text="Search by Field" Value=1 />
<asp:ListItem Text="Search between dates" Value=2 />
<asp:ListItem Text="Search Most recent Num days" Value=3 />
</asp:DropDownList><br />
This would be the default list that all user would see. If a Adin logged in,
I wanted to add a few more items to the list using the follwoing code in the
usercontrol:
cmbOptions.Items.Add(New ListItem("Search by UserId", "4"))
cmbOptions.Items.Add(New ListItem("Awaiting Approval", "5"))
If I check the count before each one, and then check after, the count does
increment, but after the page re-renders, the two exrta items are not listed.
Am I missing something. This is driving me crazy. BTY, EnableViewState is
enabled for the dropdownlist control if that makes a difference in this case.
Thanks for any suggestions.
Michael

Apr 26 '06 #2
Hi Peter,
Thanks for the reply. I can't use the load event of the usercontrol because
the search usercontrol is loaded along with the master page. Once everything
is rendered, the user would login and then I would find out if the user is
admin or not. For another purpose, I had setup a event for the login
usercontrol to kick off and pass the UserInfo to the event. One thing I did
try was to call a function in the POSearch control to add the new items if
the user is admin, but that failed also(without error), the new items just
don't display. Does this make since?
This is the sequence of events:
1. User logs in. Login User control kicks off event.
2. Master Page captures the event.
3. Master Page event calls POSearch.SetUser (not current function name, I'm
at home and can't remember the name of function)
4. POSearch then should Add new items to the dropdownlist like so:
cmbOptions.Items.Add(New ListItem("Search by UserId", "4"))
cmbOptions.Items.Add(New ListItem("Awaiting Approval", "5"))
This is where something goes wrong. I can check the item count and it will
be correct right after these two commands are run. Why the new items don't
show is really confusing me. Thanks again for the reply.
Michael

"Peter Bromberg [C# MVP]" wrote:
I think you've run into the classic misunderstanding that when a page posts
back, you need to "reconstitute" any custom items you've added to your
control in the interim.

So for example, in your page_load you might do something like

if( User.IsInRole("Admins")
{
AddBackMyExtraOptions();
}

Hoipe that helps.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Michael" wrote:
Hi again,
I really hope that there is a simple solution to this one, cause I'm having
simular things happening to other controls on this usercontrol. I have the
following control:
<asp:DropDownList ID="cmbOptions" runat="server" Width="195px">
<asp:ListItem Text="Search by PO ID" Value=0 Selected="True"
/>
<asp:ListItem Text="Search by Field" Value=1 />
<asp:ListItem Text="Search between dates" Value=2 />
<asp:ListItem Text="Search Most recent Num days" Value=3 />
</asp:DropDownList><br />
This would be the default list that all user would see. If a Adin logged in,
I wanted to add a few more items to the list using the follwoing code in the
usercontrol:
cmbOptions.Items.Add(New ListItem("Search by UserId", "4"))
cmbOptions.Items.Add(New ListItem("Awaiting Approval", "5"))
If I check the count before each one, and then check after, the count does
increment, but after the page re-renders, the two exrta items are not listed.
Am I missing something. This is driving me crazy. BTY, EnableViewState is
enabled for the dropdownlist control if that makes a difference in this case.
Thanks for any suggestions.
Michael

Apr 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DC Gringo | last post by:
I'm having such a problem with this DropDownList in a user control that is posting back and throwing an error: System.Web.HttpException: A DropDownList cannot have multiple items selected ...
4
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the...
1
by: needin4mation | last post by:
I have a dropdownlist that I want to default to the proper value in the list. It should be what the current value of the label is before I press edit. Any ideas?
1
by: Nathan Sokalski | last post by:
I have a problem that is driving me crazy. I have a User Control composed of three DropDownLists that will be used to select a date. I have everything working except for one thing. When I select a...
1
by: Frank | last post by:
Hello, I have some text boxes and 2 drop down lists (DDL) within a panel like so: Everything updates fine but the values from the DDLs are always the items selected by default. In other words,...
5
by: maurban | last post by:
Hi there experts, I have a gridview with a couple textboxes and a dropdownlist. I'm trying to insert a default value into my database driven dropdownlist. I'm doing this in the rowdatabound...
3
by: Iain | last post by:
Hi All I have 2 DropDownList boxes on a page. The first (id= "Operation") is populated on PageLoad with the contents of a database table. The second id="WorkStations" will not be populated...
1
by: Jack | last post by:
Hello, I have a dropdownlist in my aspx page: <asp:DropDownList ID="DDLProjects" runat="server"><asp:ListItem Text ="TEST9" Value ="TEST9"/></asp:DropDownList> Then in my Page_Load I have:...
2
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.