Administrator

Administrator

  • Tech Writer
  • 2.2k
  • 1.5m

Help - How to sort a datagrid's column?

Apr 8 2003 3:16 AM
Hi to all, I am new in this forum and I'm trying to resolve this problem: I have a domain in wich I created 700 user account. The first problem was to view all users of active directory (this function properly). The second step is to sort the User Name column. I tried the same method used when I want to sort the articles in a DB, but it don't work. You can help me? This is the 2 pages I created: - .aspx - ... - .aspx.cs - using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.DirectoryServices; namespace ADSI { /// /// Descrizione di riepilogo per adsi_vista. /// public class ElencoUtentiTabella : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid DataGrid2; protected System.Web.UI.WebControls.DataGrid DataGrid1; protected DirectoryEntry de; protected DataSet ds; private void Page_Load(object sender, System.EventArgs e) { DirectorySearcher src = new DirectorySearcher("(&(objectCategory=Person)(objectClass=user))"); //DataTable for users DataTable tbUsers = new DataTable("users"); //Create Columns for DataTable. tbUsers.Columns.Add("UserName",System.Type.GetType("System.String")); ds.Tables.Add(tbUsers); //DataTable for properties DataTable tbProperties = new DataTable("properties"); //Create Columns for DataTable. tbProperties.Columns.Add("PropertyName",System.Type.GetType("System.String") ); tbProperties.Columns.Add("PropertyValue",System.Type.GetType("System.String" )); ds.Tables.Add(tbProperties); src.SearchRoot = de; src.SearchScope = SearchScope.Subtree; foreach(SearchResult res in src.FindAll()) { System.Collections.IDictionaryEnumerator ien = res.Properties.GetEnumerator(); DataRow topRow = ds.Tables["users"].NewRow(); topRow["UserName"] =res.Properties["Name"][0]; ds.Tables["users"].Rows.Add(topRow); } DataGrid1.DataSource = ds.Tables["users"]; DataGrid1.DataBind(); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.de = new System.DirectoryServices.DirectoryEntry("LDAP://DOMINIO/CN=Users,DC=DOMINIO, DC=IT","administrator","prova123"); this.ds = new System.Data.DataSet(); ((System.ComponentModel.ISupportInitialize)(this.ds)).BeginInit(); this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged); // // ds // this.ds.DataSetName = "NewDataSet"; this.ds.Locale = new System.Globalization.CultureInfo("en-AU"); this.Load += new System.EventHandler(this.Page_Load); ((System.ComponentModel.ISupportInitialize)(this.ds)).EndInit(); } #endregion ...