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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with gridview

Status
Not open for further replies.

jwrz200t

Programmer
Joined
Aug 1, 2006
Messages
19
Location
US
Iam new to asp.net and Iam trying to bring my LDAP values on to a grid view. When I run my application iam not able to see the grid (the page turns up empty) what could be the possible reason??


public DataSet Userlogin(string sFilter, string[] columns, string path, bool useCached)

{

// trying to retrieve data from cache

string ulid = Session["id"].ToString();

string password = Session["password"].ToString();

HttpContext context = HttpContext.Current;

DataSet usersDS = (DataSet)context.Cache[sFilter];

if ((usersDS == null) || (!useCached))

{

//setup searching entries

DirectoryEntry deParent = new DirectoryEntry(path, ulid, password);

deParent.AuthenticationType = AuthenticationTypes.Secure;

DirectorySearcher ds = new DirectorySearcher(deParent, sFilter, columns);

ds.PageSize = 1000;

using (deParent)

{

//setup dataset that will store the results

usersDS = new DataSet("userDS");

DataTable dt = usersDS.Tables.Add("users");

DataRow dr;

// adding each property as a column

foreach (string prop in columns)

{

dt.Columns.Add(prop, typeof(string));

}

using (SearchResultCollection src = ds.FindAll())

{

foreach (SearchResult sr in src)

{

dr = dt.NewRow();

foreach (string prop in columns)

{

if (sr.Properties.Contains(prop))

{

dr[prop] = sr.Properties[prop][0];

}

}

dt.Rows.Add(dr);

}



}

}

// cache it for later, with 3 minutes sliding window

context.Cache.Insert(sFilter, usersDS, null, DateTime.MaxValue, TimeSpan.FromSeconds(180));

}

return usersDS;
}

protected void Page_Load(object sender, EventArgs e)

{
lblulid.Text = Session["id"].ToString();

string username = Session["id"].ToString();

string query = "(|(cn=" + username + ") (userPrincipalName= " + username + "ad.ilstu.edu))";

string[] columns = new string[] { "givenname", "sn", "physicalDeliveryOfficeName", "telephoneNumber", "mail", "cn" };

string ldapPath = "LDAP:// ";

GridView1.Visible = true;

DataSet ds = Userlogin(query, columns, ldapPath, true);

GridView1.DataSource = ds;

GridView1.DataBind();

}


<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"

AutoGenerateColumns="true" CellPadding="4" ForeColor="#333333" GridLines="None"

Style="z-index: 100; left: 161px; position: absolute; top: 211px" EnableViewState="true" >
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top