Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datatable not showing the value in the GridView

Status
Not open for further replies.

pusalaanita

IS-IT--Management
Feb 22, 2006
12
NO

Hello,

I am tyring to retrieve data from Active Directory and dipalying in a datatable and adding it to the GridView.
The Datatable is added to the gridview but the values r not dipalyed.
Below is the code could anyone trace out the problem and solve the problem.


public DataTable GetUsers()
{
DataTable dt = new DataTable();
dt.Columns.Add("Navn");
dt.Columns.Add("Direktenr");
dt.Columns.Add("Telefon");
dt.Columns.Add("Faks");
dt.Columns.Add("Mobil");
dt.Columns.Add("StreetAddress");
dt.Columns.Add("PostalAddress");
dt.Columns.Add("EPost");
DirectoryEntry de = GetDirectoryEntry();
DirectorySearcher ds = new DirectorySearcher(de);

ds.Filter="(objectClass=user)";

ds.SearchScope = SearchScope.Subtree;
SearchResultCollection results= ds.FindAll();
foreach (SearchResult result in results)
{
DataRow dr = dt.NewRow();
DirectoryEntry dey = GetDirectoryEntry();
dr["Navn"] = dey.Properties["cn"].Value;
dr["Direktenr"] = dey.Properties["telephonenumber"].Value;
dr["Telefon"] = dey.Properties["homephone"].Value;
dr["Faks"] = dey.Properties["facsimailtelephone"].Value;
dr["Mobil"] = dey.Properties["mobile"].Value;
dr["StreetAddress"] = dey.Properties["streetAddress"].Value;
dr["PostalAddress"] = dey.Properties["postalcode"].Value;
dr["EPost"] = dey.Properties["mail"].Value;

dt.Rows.Add(dr);
dey.Close();

}
de.Close();
return dt;

}
 
Why don't you take your own idea, and trace the code? See if you are getting data, if the dt is being populated.. etc.
 
The dt is being populated , column headers are displayed absolutely no problem, but the values are not diplayed.I dont know if anything else to be done for the values to be appended to the datarow.
 
where is the code to add the dt as the grid's datasource? where are you binding the grid?
 
The datatable is in .cs file and the gridview is being binded in the default.aspx.cs in the PageLoad
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ActiveDirectory;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FillGridView();
}
public void FillGridView()
{

ADUser objADUser = new ADUser();
DataTable dtUsers = objADUser.GetUsers();
GridView1.DataSource = dtUsers;
GridView1.DataBind();
}

}
 
trace the page load and see if you have results in the dtUsers datatable
 
There is your problem. Now you need to trace down and find out where and why you are not getting data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top