Click here to Skip to main content
16,007,885 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to apply css to rowstyle of gridview?

i used

C#
grvShowhistory.RowStyle.CssClass = "lnknew";

but not working

please help
Posted
Updated 17-Jan-12 1:30am
v3

There are several way to do that

1- designer page - itemstyle

you can make difference between even and odd rows if you want
XML
<itemstyle cssclass="lnknew" />
<alternatingitemstyle cssclass="lnknew" />


2- code behind - itemstyle usually in a init() method on pageload
C#
grvShowhistory.HeaderStyle.CssClass = "lnknew";
grvShowhistory.RowStyle.CssClass = "lnknew";


3- code behind - itemdatabound (make sure to have an itemdataboud method in the designer page
C#
protected void dgv_ItemDataBound(object sender, DataGridItemEventArgs e)
{
    switch (e.Item.ItemType)
    {
        case ListItemType.Item:
        case ListItemType.AlternatingItem:
            if(yourCondition)
            {
                e.Item.CssClass += "lnknew";
            }
            break;
    }
}


4- code behind - free code
C#
foreach (GridViewRow row in grvShowhistory.Rows)
{
    row.CssClass = "lnknew";
}



this will be
HTML
<table>
<tr class="lnknew">
<td>
</td>
...


if you need to style the TD element you have to do match the element in the row

bye
 
Share this answer
 
v4
 
Share this answer
 
hello,

you can apply in this way in gridview:

ASP.NET
<asp:GridView id="grid" runat="server" AutoGenerateColumns="False" > 
<Columns>
...
</Columns>
<Rowstyle height="26px" CssClass="lnknew" />
</asp:GridView>

hope this will help you.
And don't forget to mark as answer if it helps. :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900