DataGrid Problems...

G

Guest

Hi Can someone please tell me why my datagrid doesn't populate with data
properly...

For some reason the DataNavigateUrlFormatString populates ok but Text
doesn't???
E.G:
Text="<%Container.DataItem(Name) %>"

I would really appritiate any help!


Inline code:::
<Columns>
<asp:HyperLinkColumn HeaderText="" DataNavigateUrlField="Name"
DataNavigateUrlFormatString="myUrl.aspx?id={0}" Text="<img
src='../images/user.gif' border='0'>" Target="_blank"></asp:HyperLinkColumn>
<asp:HyperLinkColumn HeaderText="Name" DataNavigateUrlField="Name"
DataNavigateUrlFormatString="{0}" Text="<%Container.DataItem(Name) %>">
</asp:HyperLinkColumn>
<asp:HyperLinkColumn HeaderText="Dept." DataNavigateUrlField="Dept."
DataNavigateUrlFormatString="{0}" Text="<%Container.DataItem(Dept.) %>">
</asp:HyperLinkColumn>
<asp:HyperLinkColumn HeaderText="Ext." DataNavigateUrlField="Ext"
DataNavigateUrlFormatString="{0}" Text="<%Container.DataItem(Ext) %>">
</asp:HyperLinkColumn>
<asp:HyperLinkColumn HeaderText="Email" DataNavigateUrlField="Email"
DataNavigateUrlFormatString="mailto:{0}" Text="<%Container.DataItem(Email)
%>">
</asp:HyperLinkColumn>
</Columns>

::CODE BEHIND::
Sub BindGrid(Optional ByVal alpha As String = "")

Dim strADPath As String
strADPath = "netdomain.usembassy.dk"

Dim de As DirectoryEntry = New DirectoryEntry("LDAP://" & strADPath,
"netadmin", "N37au7h0R")
Dim src As DirectorySearcher

If alpha = "" Then
DataGrid1.AllowPaging = True
src = New
DirectorySearcher("(&(objectCategory=Person)(objectClass=user))")
Else
DataGrid1.AllowPaging = False
src = New
DirectorySearcher("(&(objectCategory=Person)(objectClass=user)(sn=" & alpha &
"*))")

End If

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


Dim dr As DataRow = ds.Tables("contacts").NewRow
dr("&nbsp;") = "<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)

Next
' Binds Contact data from Active Directory to DataGrid
DataGrid1.DataSource = ds.Tables("contacts")
DataGrid1.DataBind()
End Sub
 
B

Brock Allen

The Text property is for a hard coded value. Use DataTextField and perhaps
DataTextFormatString for the text for the hyperlink.
 
G

Guest

You can try following code:

<asp:HyperLinkColumn HeaderText="Name" DataNavigateUrlField="Name"
DataNavigateUrlFormatString="{0}" DataTextField= "Name" >
</asp:HyperLinkColumn>

HTH

Elton Wang
(e-mail address removed)
 

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

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top