473,396 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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

Nov 18 '05 #1
1 1958
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.

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jongmin | last post by:
Hi! I am making HyperLinkColumn in datagrid. It is simple to make the hyerlinkcolumn with one datafield. <asp:HyperLinkColumn Text="NAME" DataNavigateUrlField="NAME"...
9
by: Paul | last post by:
Hi I have a data grid with a hyperlink column. the colum has numbers like 00001,000002, ect. Just wondering how to get the text value of the cell as tempstring =...
3
by: Tim::.. | last post by:
I keep getting the following error when trying to do the following! 'DataBinding' is not an event of 'System.Web.UI.WebControls.HyperLinkColumn'. How do I get the value Name into the...
4
by: cooltech77 | last post by:
hi all, I am a newbie and i need some help.I have datagrid on my asp.net page which has hyperlink columns. the datagrid configuration in the aspx page is as follows <asp:DataGrid...
1
by: Craig | last post by:
I have a datagrid with a couple of columns. Right now, I'm setting assigning the dataview to the datasource. For the HyperLinkColumn.... <asp:HyperLinkColumn...
4
by: Joe | last post by:
Hello, I have a datagrid in an nested html table (one table inside of another table) and have set the allowsSorting property to true. I've created in the code-behind a method (Sub - I'm using...
0
by: TB | last post by:
Hi All For reasons unknown to me, the Page.IsPostBack is always false when I click a link in a hyperlink column of a datagrid which is created programmatically. My code in a page called...
1
by: arun.hallan | last post by:
Hi, I have a DataTable with say three items, an structureid, a name and description. Then i have a datagrid with one hyperlink which uses the id. The code in the page is: ...
1
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
in web form design (C#), I draged a datagrid onto web form, called grdFiles, and set aotuGenerateColumns property to FALSE. Use the following to populate data into the datagrid: //...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.