Solved

Using a drop down list in ASP.NET with ListItemCollection.

Posted on 2007-04-06
5
644 Views
Last Modified: 2013-11-26
Hello, in a class called UserNames, i have the following

  public static ListItemCollection GetUserListItems(ProfileCommon Profile) {
    ListItemCollection Items = new ListItemCollection();

    System.Web.Profile.ProfileInfoCollection pic = System.Web.Profile.ProfileManager.GetAllProfiles(System.Web.Profile.ProfileAuthenticationOption.All);
    foreach (System.Web.Profile.ProfileInfo prof in pic) {
      ListItem Item = new ListItem();

      Item.Value = Profile.GetProfile(prof.UserName.ToString()).UserName.ToString();

      Item.Text = Profile.GetProfile(prof.UserName.ToString()).LastName.ToString() + ", " +
        Profile.GetProfile(prof.UserName.ToString()).FirstName.ToString() + " (" +
        Profile.GetProfile(prof.UserName.ToString()).UserName.ToString() + ")";
      Items.Add(Item);
    }
    return Items;
  }

in my web form code i have the following under page_load

      drpOwner.DataSource = UserNames.GetUserListItems(Profile);
      drpOwner.DataBind();
      Response.Write(drpClient.SelectedValue.ToString());  //<--- Shows the full name, not just what should be (should just be a username) in the value from the static function (above)
      drpClient.SelectedValue = "test"; //<-- Comes back as saying this is a null item.  Should not be.
      Response.Write(drpClient.SelectedItem.Value.ToString());
0
Comment
Question by:wd006451
  • 2
  • 2
5 Comments
 
LVL 1

Author Comment

by:wd006451
ID: 18866830
Also is what im trying to do is just set the default username to the username of "test"
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 500 total points
ID: 18867153
Try:

drpOwner.DataSource = UserNames.GetUserListItems(Profile);
drpOwner.datatextfield = "text";
drpOwner.datavaluefield="Value";
drpOwner.DataBind();
0
 
LVL 1

Author Comment

by:wd006451
ID: 18867511
Thanks, can you exlpain that a little bit more?  It worked, but im not sure what/why im doing that?
0
 
LVL 14

Expert Comment

by:existenz2
ID: 18867783
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 18867970
Basically you are assigning which filed in the ListItemCollection should be used as the text and which field should be used as the value.

You would think that since the text field is named text and the value field named value that it would work automatically, but it does not when binding to a ListItemCollection.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question