Results 1 to 4 of 4

Thread: datagrid

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    London
    Posts
    678

    datagrid

    Hi,
    I am using a web datagrid which is populated with data.
    There are several columns on this grid.
    The last one is a template column which is used so that when you hover over it it builds a string and retrieves the values of two of the columns in the grid.
    There are several records.
    Most of the records have all the fields populated but a few do not.
    This datagrid is in a web uservontrol which is under a folder called UserControl.

    When I hover over a record which has all the fields populated, at the bottom it shows the correct path to go to if it is clicked.
    The problem is that if I hover over a record which does not have all the fields populated then it wants to go to the usercontrol folder and ofcourse the default.aspx is not there but out side it.

    This is what I am using to build the link. I think the problem is to do with putting / or . before the default.aspx

    Can you help?
    Hope this is clear. Thanks
    <asp:TemplateColumn HeaderText="Details">
    <ItemTemplate>
    <asp:HyperLink runat="server" Text="view" NavigateUrl='<%# "default.aspx?id=" + DataBinder.Eval(Container, "DataItem.nID") + "&DateOfData=" + DataBinder.Eval(Container, "DataItem.tDateOfData") %>' >
    </asp:HyperLink>
    </ItemTemplate>
    </asp:TemplateColumn>

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    To make it easier to debug (and keep presentation layer just for presentation), I usually just populate these items all on the code-behind. However, you can populate just one thing in your datagrid from the code-behind, just be sure not repopulate it on the aspx side.

    On the code-behind, use the Item_DataBound event to populate your hyperlink:
    VB Code:
    1. Private Sub Item_DataBound(Sender As Object, e As DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
    2.  
    3. If e.Item.ItemType = ListItem or e.Item.ItemType = AlternatingItem Then
    4.  
    5. Dim dbr As System.Data.Common.DbRecord = DirectCast(e.Item.DataItem, System.Data.Common.DbRecord)
    6.  
    7. Dim h As HyperLink = DirectCast(e.Item.FindControl("idofyourhyperlink"),HyperLink)
    8. 'you could also use DirectCast(e.Item.Controls(1)) instead of FindControl
    9.  
    10. h.NavigateURL = String.Concat("default.aspx?id=" , dbr(0),""&DateOfData=",dbr(1))
    11.  
    12. h.Text= "View"
    13.  
    14. End If

    In your aspx:
    VB Code:
    1. <asp:TemplateColumn HeaderText="Details">
    2. <ItemTemplate>
    3. <asp:HyperLink runat="server" id="idofyourhyperlink"  >
    4. </asp:HyperLink>
    5. </ItemTemplate>
    6. </asp:TemplateColumn>

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    London
    Posts
    678
    How is it possible to disable the link if one of the fields is empty?
    Thanks

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    You will have to check which gives the results you want:

    VB Code:
    1. 'might render just a label (span)
    2. h.Enabled = False
    3.  
    4. 'will not render the link at all
    5. h.Visible = False

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width