Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

populating ddl and setting selectedvalue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
J - 24 Mar 2008 16:07 GMT
When a button is clicked, I want to populate multiple ddl's and under
certain circumstances I want to set the SelectedValue.  I've tried different
variations of this:

protected void btnImport_Click(object sender, EventArgs e)
{
  [snip]
  int tblcols = dsCsv.Tables["csv"].Columns.Count;

  for(int i=0; i<tblcols; i++)
  {
       ListItem liItem = new ListItem();
       liItem.Text = dsCsv.Tables["csv"].Columns[i].ToString();
       liItem.Value = dsCsv.Tables["csv"].Columns[i].ToString();
       ddlAddress.Items.Add(liItem);
       ddlOrganization.Items.Add(liItem);

       if (liItem.Text.ToLower().IndexOf("company") >=0)
      {
          ddlOrganization.Items.FindByText(liItem.Text).Selected = true;
       }
    }
}

This doesn't work.  Although items were added, the code won't recognize
these items until the entire btnImport_Click is finished.  How can I
accomplish this?

Thanks.
Eliyahu Goldin - 24 Mar 2008 17:13 GMT
Sharing ListItems is a bad idea. The problem is that Selected is a property
of an ListItem rather than the ddl the item belongs to. It means that as
soon as you select an item in one list, it will become selected also in
another list.

Create separate instances if ListItems for every list.

Signature

Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

> When a button is clicked, I want to populate multiple ddl's and under
> certain circumstances I want to set the SelectedValue.  I've tried
[quoted text clipped - 25 lines]
>
> Thanks.
J - 25 Mar 2008 20:56 GMT
Ah, this bit of info solves my issues.  Thanks.

> Sharing ListItems is a bad idea. The problem is that Selected is a
> property of an ListItem rather than the ddl the item belongs to. It means
[quoted text clipped - 32 lines]
>>
>> Thanks.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.