Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid

Status
Not open for further replies.

fmardani

Programmer
Jul 24, 2003
152
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>
 
to avoid path issues use Server.MapPath.

but it's quite unclear to me why it behaves like this. please post an example of URL for a record with all fields filled with data and one with a record that does not have the fields populated.

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
So i assume that if one of the expressions is empty then you want to display nothing here? the best place to start may be to only display the link if you have both the id and date,

<asp:HyperLink runat="server" Text="view" NavigateUrl='<%# iif((DataBinder.Eval(Container, "DataItem.nID")<>"" AND DataBinder.Eval(Container, "DataItem.tDateOfData")),"default.aspx?id=" + DataBinder.Eval(Container, "DataItem.nID") + "&DateOfData=" + DataBinder.Eval(Container, "DataItem.tDateOfData"),"#") %>' >

This should make the link a "#" if both bits of data do not have any content (empty string). Syntax may be a little off. In case you havent seen the IIF statement before the syntax is

IIF(Expression, DoneIfTrue, DoneIfFalse)

Its a useful command to know, eg IIF(chkBox1.checked, 1, 0) will give 1 or 0 depending on the value of the checkbox.

 
The IIF is a good idea.
As I am using C#, can you convert it to c# please?
Thanks
 
There is no IIF statement in C# however you can use

int result = (checkbox1.checked) ? "1" : "0";

to achive the same result,

Regards,

S.
 
How is it possible to disable the link if one of the fields is empty?
Thanks
 
you can either make it blank or add an # before it.

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
If you give the server-side hyperlink a name you can acutally just hide it, eg

(expression) ? "default.aspx?..." : myHyperlink.visible=false;

i think that should work, give it a try, if you still want the link you could just disable etc...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top