G
Guest
Hi,
Can someone tell me how I sort a datagrid when using ActiveDirectory as my
Datasource! I would like to be able to add sorting to my datagrid but don't
know how to achive it!
Thanks for any advice!
Dim src As DirectorySearcher = New
DirectorySearcher("(&(objectCategory=Person)(objectClass=user))")
createTable()
src.SearchRoot = de
src.SearchScope = SearchScope.Subtree
For Each res As SearchResult In src.FindAll
Dim topRow As DataRow = ds.Tables("contacts").NewRow
topRow(" ") = "<img src='../images/user.gif'>"
If res.Properties.Contains("sn") And
res.Properties.Contains("givenName") And res.Properties.Contains("Initials")
Then
topRow("Name") = CStr(res.Properties("givenName")(0)) & ", "
& CStr(res.Properties("sn")(0)) & " " & CStr(res.Properties("Initials")(0))
Else
topRow("Name") = ""
End If
If res.Properties.Contains("physicalDeliveryOfficeName") Then
topRow("Dept.") =
CStr(res.Properties("physicalDeliveryOfficeName")(0))
Else
topRow("Dept.") = ""
End If
If res.Properties.Contains("telephoneNumber") Then
topRow("Ext") = CStr(res.Properties("telephoneNumber")(0))
Else
topRow("Ext") = ""
End If
If res.Properties.Contains("mail") Then
topRow("Email") = CStr(res.Properties("mail")(0))
Else
topRow("Email") = ""
End If
ds.Tables("contacts").Rows.Add(topRow)
Next
DataGrid1.DataSource = ds.Tables("contacts")
DataGrid1.DataBind()
End Sub
Private Sub createTable()
Dim tbcontacts As DataTable = New DataTable("contacts")
tbcontacts.Columns.Add(" ", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Name", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Dept.", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Ext", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Email", System.Type.GetType("System.String"))
ds.Tables.Add(tbcontacts)
End Sub
Can someone tell me how I sort a datagrid when using ActiveDirectory as my
Datasource! I would like to be able to add sorting to my datagrid but don't
know how to achive it!
Thanks for any advice!
Dim src As DirectorySearcher = New
DirectorySearcher("(&(objectCategory=Person)(objectClass=user))")
createTable()
src.SearchRoot = de
src.SearchScope = SearchScope.Subtree
For Each res As SearchResult In src.FindAll
Dim topRow As DataRow = ds.Tables("contacts").NewRow
topRow(" ") = "<img src='../images/user.gif'>"
If res.Properties.Contains("sn") And
res.Properties.Contains("givenName") And res.Properties.Contains("Initials")
Then
topRow("Name") = CStr(res.Properties("givenName")(0)) & ", "
& CStr(res.Properties("sn")(0)) & " " & CStr(res.Properties("Initials")(0))
Else
topRow("Name") = ""
End If
If res.Properties.Contains("physicalDeliveryOfficeName") Then
topRow("Dept.") =
CStr(res.Properties("physicalDeliveryOfficeName")(0))
Else
topRow("Dept.") = ""
End If
If res.Properties.Contains("telephoneNumber") Then
topRow("Ext") = CStr(res.Properties("telephoneNumber")(0))
Else
topRow("Ext") = ""
End If
If res.Properties.Contains("mail") Then
topRow("Email") = CStr(res.Properties("mail")(0))
Else
topRow("Email") = ""
End If
ds.Tables("contacts").Rows.Add(topRow)
Next
DataGrid1.DataSource = ds.Tables("contacts")
DataGrid1.DataBind()
End Sub
Private Sub createTable()
Dim tbcontacts As DataTable = New DataTable("contacts")
tbcontacts.Columns.Add(" ", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Name", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Dept.", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Ext", System.Type.GetType("System.String"))
tbcontacts.Columns.Add("Email", System.Type.GetType("System.String"))
ds.Tables.Add(tbcontacts)
End Sub