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" <an*******@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
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.