CodeVerge.Net Beta
Login Idy
Register Password
  Forgot?
Explore    Item Entry    Members   
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML





Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 8/6/2005 4:55:15 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 2 Views: 26 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
3 Items, 1 Pages 1 |< << Go >> >|
edmars
Asp.Net User
Listbox and Dropdownlistbox8/6/2005 4:55:15 AM

0/0

Hi,
I know these aren't new server controls, but this was the most appropriate forum I found. Is anyone else having a problem with using these controls programmatically? My specific example is as follows:

I am populating a DropDownListBox with the following code:

protected void Page_Load(object sender, EventArgs e)
{
   ddlRoles.DataSource =
Roles.GetAllRoles();
   ddlRoles.DataBind();
   //other code after this
}

and then accessing the control to get the role selected by the user using the following code:

protected void btnCreateUser_Click(object sender, EventArgs e)
{
   
string selectedRole = ddlRoles.SelectedValue;
   //other code after this
}

The roles I have created using the website configuration tool are "Administrator" and "Agent" and they both appear in the DropDownListBox ddlRoles, but ddlRoles.SelectedValue will only ever return "Administrator". Do I need to do some ViewState stuff here perhaps for it to remember the value of the ListBox, or why isn't it returning the correct selected value?

Thanks a lot,
Eddie

BrockAllen
Asp.Net User
Re: Listbox and Dropdownlistbox8/6/2005 11:53:42 PM

0/0

Change:
protected void Page_Load(object sender, EventArgs e)
{
   ddlRoles.DataSource =
Roles.GetAllRoles();
   ddlRoles.DataBind();
   //other code after this
}

To:
protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostback) {
   ddlRoles.DataSource =
Roles.GetAllRoles();
   ddlRoles.DataBind();
   //other code after this
  }
}

When there's a posback you don't (normally) need to re-populate server controls. They maintain their data automatically across postback. What was happening is that you were rebuilding the control, and once rebuilt it's value is simply the first one in the list.

-Brock

DevelopMentor
http://staff.develop.com/ballen
edmars
Asp.Net User
Re: Listbox and Dropdownlistbox8/7/2005 2:20:15 AM

0/0

Great, thanks for the help, Brock.

-Eddie
3 Items, 1 Pages 1 |< << Go >> >|



Search This Site:


Meet Our Sponsors:



Other Resources:

Why cells are huge ? - general_asp.net.data_presentation_controls - Web ... Using DropDownListbox.SelectedValue = "Medium" to Default DropDownList Box Selected Value ... How to handle insert and ListBox from a GRID??? Calendar page? ...
41 seconds and wierd NTP - novell.support.bordermanager.install-setup ... Javascript function to display multiselected values of a listbox ... How to set the focus into dropdownlistbox. modal popup. Is installing into the GAC required? ...
Control API for Dropdown List Box (dropdownListBox) Defines the items in a dropdownListBox or listBox instead of the model. key ... Defines the text string displayed in the dropdownListBox or listBox. ...
DropDownListBox DropDownListBox supported list. PowerObject. Control. ListBox ... DropDownListBox. System.Windows.Forms.ListBox. Yes. Properties. Accelerator. No. AllowEdit ...
Control API for List Box (listBox) Control API for List Box (listBox) A set of choices from which ... Defines the items in a dropdownListBox or listBox instead of the model. See dropdownListBox. ...
Working with DropDownList and ListBox Controls in ASP.NET ... we'll see how to use DropDownList and ListBox Web controls to display data in various ... Office and VB.NET. Pocket PC. Printing. Security. Strings & Arrays ...
ListBox Class Renders a list box that allows single or multiple item selection. ListBox Class Members ... See Also. DropDownListBox, ListControl, ListItem. Books and more ...
Nabble - RE: How can i fill 4 dropdownlistbox(combobox) accordingly ... RE: How can i fill 4 dropdownlistbox(combobox) accordingly from one to another?. Thanks very much !! I will keep ... was filled listbox academies that exist ...
Nabble - RE: How can i fill 4 dropdownlistbox(combobox) accordingly ... RE: How can i fill 4 dropdownlistbox(combobox) accordingly from one to another?. Hello David Im finishing the tutorial ... was filled listbox academies that ...
DROP DOWN LIST BOX how to seperat the concated string? that separated string how can we bind with dropdownlistbox? ... DROP DOWN LIST BOX. Posted Date: 29 Jul 2008 Total Responses: 1 ...
: Class DropDownListBoxWidget ... the dropdown, if a color is null the default color of this listbox will be used ... A dropdownlistbox can be plain, boxed, filled or underlined. See Also: ...
Rational Robot Tutorial: Capturing Data in a DropDownDataWindow << How to Hidden DataWindows | Capturing Data in a ListBox > ... To capture the data in a DropDownDataWindow or DropDownListBox, use the ...


 
All Times Are GMT