Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Can't apply CSS class to DataGrid's HyperlinkColumn?

Reply
Thread Tools

Can't apply CSS class to DataGrid's HyperlinkColumn?

 
 
=?Utf-8?B?RGF2ZQ==?=
Guest
Posts: n/a
 
      02-27-2004
I have a hyperlink column in a datagrid as follows

<asp:HyperLinkColumn DataNavigateUrlField="OrderId" DataNavigateUrlFormatString="OrderDetails.aspx?Id= {0}" DataTextField="Order" HeaderText="Order" ItemStyle-CssClass="Green10pt"></asp:HyperLinkColumn

renders
...
<td class="Green10pt"><a href=OrderDetails.aspx?Id=398365">ABC Corp</a></td>..

How can I get the class to be added to the anchor <a> tag not in the outer <td> element? ItemStyle-CssClass is not doing what I thought it would

Dave

 
Reply With Quote
 
 
 
 
Martin Dechev
Guest
Posts: n/a
 
      02-27-2004
Hi, Dave,

The easier way is to use a template column.

A little bit harder is to attach to the ItemCreated event of the DataGrid
and then cast appropriately the instance in e.Item.Cells[n].Controls[0] (in
VB e.Item.Cells(n).Controls(0) ) where n is the index (zero-based) of the
column. You should also check if e.Item.ItemIndex is different from -1 (-1
means it is the header or the footer row). Something like:

[C#]
protected void Item_Created(object s, DataGridItemEventArgs e)
{
if(e.Item.ItemIndex != -1)
{
// try HtmlControl or WebControl
((HtmlControl)e.Item.Cells[n].Controls[0]).Attributes["class"] =
"Green10pt";
}
}

[VB.NET]
Sub Item_Created(ByVal s As Object, ByVal e As DataGridItemEventArgs)
If e.Item.ItemIndex <> -1 Then
' try HtmlControl or WebControl
CType(e.Item.Cells(n).Controls(0), HtmlControl).Attributes("class") =
"Green10pt"
End If
End Sub

Hope this helps
Martin
"Dave" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have a hyperlink column in a datagrid as follows:
>
> <asp:HyperLinkColumn DataNavigateUrlField="OrderId"

DataNavigateUrlFormatString="OrderDetails.aspx?Id= {0}" DataTextField="Order"
HeaderText="Order" ItemStyle-CssClass="Green10pt"></asp:HyperLinkColumn>
>
> renders:
> ...
> <td class="Green10pt"><a href=OrderDetails.aspx?Id=398365">ABC

Corp</a></td>...
>
> How can I get the class to be added to the anchor <a> tag not in the outer

<td> element? ItemStyle-CssClass is not doing what I thought it would.
>
> Dave.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to apply ACL to a management port (CSS) fangyong.F@gmail.com Cisco 2 01-05-2006 06:21 AM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Apply style changes to a whole CSS class Waffeloo Javascript 3 09-19-2005 11:34 PM
how to apply css class style to web controls =?Utf-8?B?bnN2a2V5YW4=?= ASP .Net 1 02-20-2004 03:47 PM
[XSLT] could not apply "apply-templates" Stefan Siegl XML 1 07-18-2003 09:43 AM



Advertisments