ListBox datasource works fine in Win Forms, but Broken in Web Forms

Hi all.

I have the following problem

I have a listbox which is bound to a datatable with two columns(about 25 rows).

In C# win forms, it works just like it says it should, but if i move the code to Web Forms, the listbox comes back empty. I have checked, and the table definitely has data.

I'm new to Web Forms though, so its entirely possible I'm missing something obvious.

Any hints?

-------------------------
Win Forms Code
-------------------------
      try {
        this.dirsearchGroups.SearchRoot = de;
        SearchResultCollection rs1 = this.dirsearchGroups.FindAll();
        dtGroups = new DataTable("groups");
        dtGroups.Columns.Add("group", System.Type.GetType("System.String"));
        dtGroups.Columns.Add("path", System.Type.GetType("System.String"));

        foreach(SearchResult rs in rs1) {
          dtGroups.Rows.Add(new object[2] {rs.Properties["cn"][0].ToString(), rs.Path.ToString()});
        }
        this.lbGroups.DataSource = dtGroups;
        this.lbGroups.DisplayMember = "group";
        this.lbGroups.ValueMember = "path";
snip--->

**WORKS LIKE A CHARM**

------------------------------
Web Forms
------------------------------
      dirsearchGroups.SearchRoot = root;
      dirsearchGroups.Filter = "(&(objectClass=group)(cn=*))";
      dirsearchGroups.PropertiesToLoad.Add("cn");

      SearchResultCollection rs1 = this.dirsearchGroups.FindAll();
      dtGroups = new DataTable("groups");
      dtGroups.Columns.Add("group", System.Type.GetType("System.String"));
      dtGroups.Columns.Add("path", System.Type.GetType("System.String"));


      foreach(SearchResult rs in rs1) {
        dtGroups.Rows.Add(new object[2] {rs.Properties["cn"][0].ToString(), rs.Path.ToString()});
      }
      Response.Write("dtGroups count " + dtGroups.Rows.Count.ToString());

      this.lbGroups.DataSource = dtGroups;
      this.lbGroups.DataTextField = "group";
      this.lbGroups.DataValueField = "path";

**THIS RETURNS AND EMPTY "ListBox" (select box on the HTML rendered form)

Can somebody clue me in please?  I'm sure its something I'm not doing..
LVL 2
SegFaultAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RiverGuyCommented:
I ran accross this too.  I ended up tossing out the data-binding and adding values to the listbox/combobox while looping through my dataset.

This  is in VB.Net, but the idea is the same in C#:

With list1
            Dim dr3 As Data.DataRow
            Dim k As Double
            k = 0
            For Each dr3 In DataSet2.Tables(0).Rows
                .Items.Add(dr3.Item(1))
                .Items.Item(k).Value = dr3.Item(0)
                k = k + 1
            Next
End With

I assigned the display value to the 2nd column in my DB, and the Value to the 1st column.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SegFaultAuthor Commented:
Here is how I did it

I'm using a DirectoryResults collection, so I just iterated through that collection and added the items.

foreach(SearchResult rs in rsCollection) {
  lbGroups.Items.Add(new ListItem(rs.Properties["cn"][0].ToString(), rs.Path.ToString());
}

worked like a charm.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.