Help on HyperlInk column ????

G

Guest

Dear all,

I have the folloeing entry for a datagrid column :

<asp:HyperLinkColumn
Text="<img border=0 src=file.gif>"
HeaderText="File"
DataNavigateUrlField="DOC_LINK"
DataNavigateUrlFormatString="{0}"
Target="_blank">
</asp:HyperLinkColumn>

My DOC_LOMK database field contains a fileName. This column is represented
in the grid by the picture defined in Text attribute.

What I would like to do is having that picture displayed only if the field
is not empty.
How to conditionnaly display the picture based on that empty conddition ?

Thnaks for your help
regards
serge
 
B

Bruno Alexandre

Why don't you use a asp:ButtonField and set the imageUrl property to the
name of the database field?



--


Thank you in Advance.

Bruno Alexandre
(a Portuguese in Denmark)
 
G

Guest

What property are you talking about ?
There is no imageurl property for an <asp:ButtonColumn>

Once again the only thing I want to do is to display a symbol when this
field is empty.
When not empty I need to create a href link

regards
 
C

carl

Serge,

You can clear the text in the OnItemDataBound event if a link is not
present:

<asp:DataGrid id="DataGrid1"
runat="server"
AutoGenerateColumns="False"
OnItemDataBound="DataGrid1_ItemDataBound">
....

protected void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
string link = drv.Row["DOC_LINK"].ToString();
if(link == null || link == string.Empty)
e.Item.Cells[1].Text = string.Empty;
}
}

-Carl
 
G

Guest

hi,

I have try what you sugest and wht it does is that it clear the field for
all my records !!!

here is my code :

If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem) Then
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
FileLink = CType(drv.Row("DOC_LINK"), String).ToString
If IsNothing(FileLink) Or FileLink = String.Empty Then
e.Item.Cells(6).Text = String.Empty
Else
e.Item.Cells(6).Text = "<img border=0 src=file.gif>"
End If
End If

any idea ?

regards
serge
 
C

carl

The code looks fine, the only reason all rows would be empty is if
DOC_LINK is null or the method is not being called. When you put a
break point on the If...Else... statement does it execute the Else
condition for rows with DOC_LINK?
 
G

Guest

When I set the break point, it handle text correctly.
I mean it set properly the text based on the value of the database field.

I guess the reason it clear all rows is that there is no text attribute for
the column in the datagrid and that the grid gets read after the databind
event, which overwrites.

AS a test I have add a text attrribute for my grid column and set it to
Text="click me"

According to what we have done if the code you sugest is in the proper grid
event, then I should get what is set in my code, but in fact the result is
that entry valeu are all set with "Click me"

For me it sounds that there is an other datagrid events which occurs after
the databindind which overwrites the all thing and get what is define by
default

regards
serge
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,061
Latest member
KetonaraKeto

Latest Threads

Top