Solved

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

Posted on 2007-04-06
5
640 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now