DataGrid Problems...

Discussion in 'ASP .Net' started by =?Utf-8?B?VGltOjouLg==?=, Jun 13, 2005.

  1. 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
    =?Utf-8?B?VGltOjouLg==?=, Jun 13, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?VGltOjouLg==?=

    Brock Allen Guest

    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)(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
    Brock Allen, Jun 13, 2005
    #2
    1. Advertising

  3. You can try following code:

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

    HTH

    Elton Wang



    "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)(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(" ") = "<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
    =?Utf-8?B?RWx0b24gVw==?=, Jun 13, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ingeborg

    DataGrid problems

    Ingeborg, Jun 28, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    427
    Luke Zhang [MSFT]
    Jul 1, 2003
  2. Susan Baker
    Replies:
    2
    Views:
    800
    kelvSYC
    Jun 26, 2005
  3. Shelly

    Problems, problems for newbie

    Shelly, Sep 2, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    2,167
    Shelly
    Sep 3, 2007
  4. Andreas Klemt
    Replies:
    0
    Views:
    267
    Andreas Klemt
    Oct 8, 2003
  5. Sak Na rede
    Replies:
    0
    Views:
    403
    Sak Na rede
    Jan 30, 2009
Loading...

Share This Page