PDA

Click to See Complete Forum and Search --> : datagrid


fmardani
Jul 14th, 2004, 05:50 AM
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>

nemaroller
Jul 14th, 2004, 06:12 AM
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:

Private Sub Item_DataBound(Sender As Object, e As DataGridItemEventArgs) Handles DataGrid1.ItemDataBound

If e.Item.ItemType = ListItem or e.Item.ItemType = AlternatingItem Then

Dim dbr As System.Data.Common.DbRecord = DirectCast(e.Item.DataItem, System.Data.Common.DbRecord)

Dim h As HyperLink = DirectCast(e.Item.FindControl("idofyourhyperlink"),HyperLink)
'you could also use DirectCast(e.Item.Controls(1)) instead of FindControl

h.NavigateURL = String.Concat("default.aspx?id=" , dbr(0),""&DateOfData=",dbr(1))

h.Text= "View"

End If


In your aspx:

<asp:TemplateColumn HeaderText="Details">
<ItemTemplate>
<asp:HyperLink runat="server" id="idofyourhyperlink" >
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>

fmardani
Jul 14th, 2004, 06:50 AM
How is it possible to disable the link if one of the fields is empty?
Thanks

nemaroller
Jul 14th, 2004, 09:12 AM
You will have to check which gives the results you want:


'might render just a label (span)
h.Enabled = False

'will not render the link at all
h.Visible = False