?
Solved

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

Posted on 2003-03-26
2
Medium Priority
?
258 Views
Last Modified: 2010-05-18
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..
0
Comment
Question by:SegFault
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
RiverGuy earned 750 total points
ID: 8213646
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
 
LVL 2

Author Comment

by:SegFault
ID: 8230125
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

752 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