Datatable to DataGrid???

G

Guest

Can someone please tell me how I put the following information into a
datagrid...

I want to be able to use templatecolumns in a datagrid to reformat the
information I have pulled from an ActiveDirectory Database! I'm just not
quite sure how to pull the info into the datagrid!

I tried...

<asp:TemplateColumn HeaderText="">
<ItemTemplate>
<asp:HyperLink Runat =server NavigateUrl
='<%#DataBinder.Eval(Container.DataItem, "givenName")%>' ID="Hyperlink1"
NAME="Hyperlink1">
<img src="../images/user.gif" border="0">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>

I would be really grateful for any tips anyone might have!

Thanks

.....CODE....

src.SearchRoot = de
src.SearchScope = SearchScope.Subtree
For Each res As SearchResult In src.FindAll


Dim dr As DataRow = ds.Tables("contacts").NewRow
dr(" ") = "<img src='../images/user.gif'>"

If res.Properties.Contains("sn") And
res.Properties.Contains("givenName") And res.Properties.Contains("Initials")
Then
dr("Name") = CStr(res.Properties("givenName")(0)) & ", " &
CStr(res.Properties("sn")(0)) & " " & CStr(res.Properties("Initials")(0))
Else
dr("Name") = ""
End If

If res.Properties.Contains("physicalDeliveryOfficeName") Then
dr("Dept.") =
CStr(res.Properties("physicalDeliveryOfficeName")(0))
Else
dr("Dept.") = ""
End If

If res.Properties.Contains("telephoneNumber") Then
Dim TeleNumber As String =
CStr(res.Properties("telephoneNumber")(0))
dr("Ext") = "#" & Right(TeleNumber, Len(TeleNumber) -
InStr(TeleNumber, "1"))
Else
dr("Ext") = ""
End If

If res.Properties.Contains("mail") Then
dr("Email") = CStr(res.Properties("mail")(0))
Else
dr("Email") = ""
End If

ds.Tables("contacts").Rows.Add(dr)
 
D

David Lozzi

Try this once the ds object is loaded.

dgDataGrid.DataSource = ds.Tables("contacts")
dgDataGrid.DataBind()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top