473,809 Members | 2,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid Problems...

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

For some reason the DataNavigateUrl FormatString populates ok but Text
doesn't???
E.G:
Text="<%Contain er.DataItem(Nam e) %>"

I would really appritiate any help!
Inline code:::
<Columns>
<asp:HyperLinkC olumn HeaderText="" DataNavigateUrl Field="Name"
DataNavigateUrl FormatString="m yUrl.aspx?id={0 }" Text="<img
src='../images/user.gif' border='0'>" Target="_blank" ></asp:HyperLinkCo lumn>
<asp:HyperLinkC olumn HeaderText="Nam e" DataNavigateUrl Field="Name"
DataNavigateUrl FormatString="{ 0}" Text="<%Contain er.DataItem(Nam e) %>">
</asp:HyperLinkCo lumn>
<asp:HyperLinkC olumn HeaderText="Dep t." DataNavigateUrl Field="Dept."
DataNavigateUrl FormatString="{ 0}" Text="<%Contain er.DataItem(Dep t.) %>">
</asp:HyperLinkCo lumn>
<asp:HyperLinkC olumn HeaderText="Ext ." DataNavigateUrl Field="Ext"
DataNavigateUrl FormatString="{ 0}" Text="<%Contain er.DataItem(Ext ) %>">
</asp:HyperLinkCo lumn>
<asp:HyperLinkC olumn HeaderText="Ema il" DataNavigateUrl Field="Email"
DataNavigateUrl FormatString="m ailto:{0}" Text="<%Contain er.DataItem(Ema il)
%>">
</asp:HyperLinkCo lumn>
</Columns>

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

Dim strADPath As String
strADPath = "netdomain.usem bassy.dk"

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

If alpha = "" Then
DataGrid1.Allow Paging = True
src = New
DirectorySearch er("(&(objectCa tegory=Person)( objectClass=use r))")
Else
DataGrid1.Allow Paging = False
src = New
DirectorySearch er("(&(objectCa tegory=Person)( objectClass=use r)(sn=" & alpha &
"*))")

End If

src.SearchRoot = de
src.SearchScope = SearchScope.Sub tree
For Each res As SearchResult In src.FindAll
Dim dr As DataRow = ds.Tables("cont acts").NewRow
dr("&nbsp;") = "<img src='../images/user.gif'>"

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

If res.Properties. Contains("physi calDeliveryOffi ceName") Then
dr("Dept.") =
CStr(res.Proper ties("physicalD eliveryOfficeNa me")(0))
Else
dr("Dept.") = ""
End If

If res.Properties. Contains("telep honeNumber") Then
Dim TeleNumber As String =
CStr(res.Proper ties("telephone Number")(0))
dr("Ext") = "#" & Right(TeleNumbe r, Len(TeleNumber) -
InStr(TeleNumbe r, "1"))
Else
dr("Ext") = ""
End If

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

ds.Tables("cont acts").Rows.Add (dr)

Next
' Binds Contact data from Active Directory to DataGrid
DataGrid1.DataS ource = ds.Tables("cont acts")
DataGrid1.DataB ind()
End Sub
Nov 19 '05 #1
2 1711
The Text property is for a hard coded value. Use DataTextField and perhaps
DataTextFormatS tring 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 DataNavigateUrl FormatString populates ok but Text
doesn't???
E.G:
Text="<%Contain er.DataItem(Nam e) %>"
I would really appritiate any help!

Inline code:::
<Columns>
<asp:HyperLinkC olumn HeaderText="" DataNavigateUrl Field="Name"
DataNavigateUrl FormatString="m yUrl.aspx?id={0 }" Text="<img
src='../images/user.gif' border='0'>"
Target="_blank" ></asp:HyperLinkCo lumn>
<asp:HyperLinkC olumn HeaderText="Nam e" DataNavigateUrl Field="Name"
DataNavigateUrl FormatString="{ 0}" Text="<%Contain er.DataItem(Nam e)
%>">
</asp:HyperLinkCo lumn>
<asp:HyperLinkC olumn HeaderText="Dep t." DataNavigateUrl Field="Dept."
DataNavigateUrl FormatString="{ 0}" Text="<%Contain er.DataItem(Dep t.)
%>">
</asp:HyperLinkCo lumn>
<asp:HyperLinkC olumn HeaderText="Ext ." DataNavigateUrl Field="Ext"
DataNavigateUrl FormatString="{ 0}" Text="<%Contain er.DataItem(Ext ) %>">
</asp:HyperLinkCo lumn>
<asp:HyperLinkC olumn HeaderText="Ema il" DataNavigateUrl Field="Email"
DataNavigateUrl FormatString="m ailto:{0}"
Text="<%Contain er.DataItem(Ema il)
%>">
</asp:HyperLinkCo lumn>
</Columns>
::CODE BEHIND::
Sub BindGrid(Option al ByVal alpha As String = "")
Dim strADPath As String
strADPath = "netdomain.usem bassy.dk"
Dim de As DirectoryEntry = New DirectoryEntry( "LDAP://" &
strADPath,
"netadmin", "N37au7h0R" )
Dim src As DirectorySearch er
If alpha = "" Then
DataGrid1.Allow Paging = True
src = New
DirectorySearch er("(&(objectCa tegory=Person)( objectClass=use r))")
Else
DataGrid1.Allow Paging = False
src = New
DirectorySearch er("(&(objectCa tegory=Person)( objectClass=use r)(sn=" &
alpha &
"*))")

End If

src.SearchRoot = de
src.SearchScope = SearchScope.Sub tree
For Each res As SearchResult In src.FindAll
Dim dr As DataRow = ds.Tables("cont acts").NewRow
dr("&nbsp;") = "<img src='../images/user.gif'>"
If res.Properties. Contains("sn") And
res.Properties. Contains("given Name") And
res.Properties. Contains("Initi als")
Then
dr("Name") = CStr(res.Proper ties("givenName ")(0)) & ",
" &
CStr(res.Proper ties("sn")(0)) & " " &
CStr(res.Proper ties("Initials" )(0))
Else
dr("Name") = ""
End If
If res.Properties. Contains("physi calDeliveryOffi ceName")
Then
dr("Dept.") =
CStr(res.Proper ties("physicalD eliveryOfficeNa me")(0))
Else
dr("Dept.") = ""
End If
If res.Properties. Contains("telep honeNumber") Then
Dim TeleNumber As String =
CStr(res.Proper ties("telephone Number")(0))
dr("Ext") = "#" & Right(TeleNumbe r, Len(TeleNumber) -
InStr(TeleNumbe r, "1"))
Else
dr("Ext") = ""
End If
If res.Properties. Contains("mail" ) Then
dr("Email") = CStr(res.Proper ties("mail")(0) )
Else
dr("Email") = ""
End If
ds.Tables("cont acts").Rows.Add (dr)

Next
' Binds Contact data from Active Directory to DataGrid
DataGrid1.DataS ource = ds.Tables("cont acts")
DataGrid1.DataB ind()
End Sub


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

<asp:HyperLinkC olumn HeaderText="Nam e" DataNavigateUrl Field="Name"
DataNavigateUrl FormatString="{ 0}" DataTextField= "Name" >
</asp:HyperLinkCo lumn>

HTH

Elton Wang
el********@hotm ail.com
"Tim::.." wrote:
Hi Can someone please tell me why my datagrid doesn't populate with data
properly...

For some reason the DataNavigateUrl FormatString populates ok but Text
doesn't???
E.G:
Text="<%Contain er.DataItem(Nam e) %>"

I would really appritiate any help!
Inline code:::
<Columns>
<asp:HyperLinkC olumn HeaderText="" DataNavigateUrl Field="Name"
DataNavigateUrl FormatString="m yUrl.aspx?id={0 }" Text="<img
src='../images/user.gif' border='0'>" Target="_blank" ></asp:HyperLinkCo lumn>
<asp:HyperLinkC olumn HeaderText="Nam e" DataNavigateUrl Field="Name"
DataNavigateUrl FormatString="{ 0}" Text="<%Contain er.DataItem(Nam e) %>">
</asp:HyperLinkCo lumn>
<asp:HyperLinkC olumn HeaderText="Dep t." DataNavigateUrl Field="Dept."
DataNavigateUrl FormatString="{ 0}" Text="<%Contain er.DataItem(Dep t.) %>">
</asp:HyperLinkCo lumn>
<asp:HyperLinkC olumn HeaderText="Ext ." DataNavigateUrl Field="Ext"
DataNavigateUrl FormatString="{ 0}" Text="<%Contain er.DataItem(Ext ) %>">
</asp:HyperLinkCo lumn>
<asp:HyperLinkC olumn HeaderText="Ema il" DataNavigateUrl Field="Email"
DataNavigateUrl FormatString="m ailto:{0}" Text="<%Contain er.DataItem(Ema il)
%>">
</asp:HyperLinkCo lumn>
</Columns>

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

Dim strADPath As String
strADPath = "netdomain.usem bassy.dk"

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

If alpha = "" Then
DataGrid1.Allow Paging = True
src = New
DirectorySearch er("(&(objectCa tegory=Person)( objectClass=use r))")
Else
DataGrid1.Allow Paging = False
src = New
DirectorySearch er("(&(objectCa tegory=Person)( objectClass=use r)(sn=" & alpha &
"*))")

End If

src.SearchRoot = de
src.SearchScope = SearchScope.Sub tree
For Each res As SearchResult In src.FindAll
Dim dr As DataRow = ds.Tables("cont acts").NewRow
dr(" ") = "<img src='../images/user.gif'>"

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

If res.Properties. Contains("physi calDeliveryOffi ceName") Then
dr("Dept.") =
CStr(res.Proper ties("physicalD eliveryOfficeNa me")(0))
Else
dr("Dept.") = ""
End If

If res.Properties. Contains("telep honeNumber") Then
Dim TeleNumber As String =
CStr(res.Proper ties("telephone Number")(0))
dr("Ext") = "#" & Right(TeleNumbe r, Len(TeleNumber) -
InStr(TeleNumbe r, "1"))
Else
dr("Ext") = ""
End If

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

ds.Tables("cont acts").Rows.Add (dr)

Next
' Binds Contact data from Active Directory to DataGrid
DataGrid1.DataS ource = ds.Tables("cont acts")
DataGrid1.DataB ind()
End Sub

Nov 19 '05 #3

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

Similar topics

9
1743
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 various comboboxes and textboxes on my form. when they are satisfied they press OK. the row is then displayed in my datagrid. I now automaticcaly want 2 link buttons to appear next to the row that allows the user to delete the row or edit it.
2
3280
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 use the F2 key to enter edit mode and then hit TAB or ESCAPE without actually editing the value, dotnet crashes with a null reference error.
3
1883
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 tablestyle and gridcolumnstyles to that tablestyle. If we have invisible columns, we add the gridcolumnstyle with Width = 0 (couldn't find any other way to do it, because there is no Visible property available...).
3
4278
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 several examples on the web. They all seem to have problems, though that I've been unable to resolve. The most promising example I have found is at:
0
1052
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: 1. When I click on one of the LinkButton column(first or last column), I activate the ItemCommand event of the dataGrid. My problem is how can I know on which column I click? The first or the last one? I need to make a different in my code when the...
5
2379
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, check boxes, date pickers, combo boxes and datagrids). I have been coding alone on this project for about a year, and I have experienced many problems which have not been addressed by various SP's, including the recent SP1 to Framework.NET 1.1,...
0
1242
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 the code for my inner datagrid's EditCommand: public void dgInner_EditCommand(object sender, DataGridCommandEventArgs e) {
3
1809
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 found on google: MyDataGrid.EnableViewState = false; MyPage.Response.Clear(); MyPage.Response.Buffer = true; MyPage.Response.AddHeader( "Content-disposition",
3
2631
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 there can advise me on how to do it. 1. The biggest problem I am finding is that the datagrid does not update the datagrid.datasource very well. When a new row is created in the datagrid it may or may not be created in the datasource as
9
2734
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 code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
0
9602
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10639
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10383
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7661
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.