Setting CssClass of sorted header <a> tags...

N

Nathan Baulch

I have a sortable DataGrid.
Where can I set a CssClass for the <a> element that results after rendering
the header row?

My rendered DataGrid header cells currently look like this:

<td>
<a href="javascript:__doPostBack('DG$_ctl1$_ctl3','')">
ColumnX
</a>
</td>

I want them to look like this:

<td>
<a href="javascript:__doPostBack('DG$_ctl1$_ctl3','')" class="myclass">
ColumnX
</a>
</td>



Cheers
Nathan
 
S

Saravana

you can set cssclass for header in Itemcreated event handler, check out the
following code snippet
Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemCreated

If e.Item.ItemType = ListItemType.Header Then

e.item.cells(0).CssClass = "<classname"

..................

end if
end sub
 
N

Nathan Baulch

If e.Item.ItemType = ListItemType.Header Then
e.item.cells(0).CssClass = "<classname"

What you code does is set the CssClass of the first <TD> in the header <TR>
element.
This is not what I'm trying to do.
I want to set the CssClass of the <A> element that is rendered *inside* the
<TD>.

Unfortunately, e.Item.Cells[0].Controls[0] for the header row is a Literal
control with an empty Text property.

Any other ideas?


Nathan
 
J

Jeff Jorczak

private void DataGrid_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
// hack to get sortable column heading to show correct style
if (e.Item.ItemType == ListItemType.Header)
{
foreach (TableCell cell in e.Item.Cells)
{
if ((cell.Controls.Count > 0) && (cell.Controls[0] != null))
{
((System.Web.UI.WebControls.LinkButton)cell.Controls[0]).CssClass
= DataGrid.HeaderStyle.CssClass;
}
}
}
}
 

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,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top