473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

DataGrid Problems...

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)(objec tClass=user))")
Else
DataGrid1.AllowPaging = False
src = New
DirectorySearcher("(&(objectCategory=Person)(objec tClass=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("physicalDeliveryOfficeNam e") 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
Nov 19 '05 #1
2 1690
The Text property is for a hard coded value. Use DataTextField and perhaps
DataTextFormatString for the text for the hyperlink.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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)(objec tClass=user))")
Else
DataGrid1.AllowPaging = False
src = New
DirectorySearcher("(&(objectCategory=Person)(objec tClass=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("physicalDeliveryOfficeNam e")
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


Nov 19 '05 #2
You can try following code:

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

HTH

Elton Wang
el********@hotmail.com
"Tim::.." wrote:
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)(objec tClass=user))")
Else
DataGrid1.AllowPaging = False
src = New
DirectorySearcher("(&(objectCategory=Person)(objec tClass=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(" ") = "<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("physicalDeliveryOfficeNam e") 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

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Lina | last post by:
Hi, Can anyone tell me if it is possible to add link buttons to a datagrid that has its source set to a datatable that i have created? i.e i want the user to be able to select a room from...
2
by: Tamlin | last post by:
Hi all, I'm getting a bug with the datagrid object. I've created one from scratch, bound it to a dataview with 2 int32 columns and formatted the output as currency. I've found that when you...
3
by: Igor Mendizabal | last post by:
Hello, We're doing our own datagrid based on the System.windows.forms.datagrid control, and are having some problems with horizontal scrolling. In general, we construct our datagrid adding a...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
0
by: THM5101 | last post by:
Hello I have two problems with my dataGrid. I created dataGrid with 4 columns. The first and the last one are LinkButton type, the second and third are Bound Column type. My problems are:...
5
by: sdbranum | last post by:
I have been using Visual C#.NET to code a large project having many data adapters, data sets, datagrids, multiple forms with tab pages, each containing various controls (mostly label, text boxes,...
0
by: Linus | last post by:
Hi, I have a datagrid nested inside another datagrid, the edit/update/cancel command works fine on the outter datagrid but I'm having problems with the inner one. There are 2 problems and here's...
3
by: nkunkov | last post by:
Hi, I have read a lot of articles in this newsgroup about how to solve this problem but found no solution. I'm trying to export a C# datagrid to Excel file. Here is my code that I have also...
3
by: simchajoy2000 | last post by:
Hi, I have been working with datagrids a lot in the past two weeks and I am running across a lot of problems. Maybe there is no way around these problems but I hope there are and someone out...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.