如何将CSS应用于gridview的行样式? [英] How to apply css to rowstyle of gridview?
问题描述
如何将CSS应用于gridview的行样式?
我用
How to apply css to rowstyle of gridview?
i used
grvShowhistory.RowStyle.CssClass = "lnknew";
但不起作用
请帮助
but not working
please help
推荐答案
有几种方法可以实现
1- 设计器页面-itemstyle
您可以根据需要在偶数行和奇数行之间进行区分
There are several way to do that
1- designer page - itemstyle
you can make difference between even and odd rows if you want
<itemstyle cssclass="lnknew" />
<alternatingitemstyle cssclass="lnknew" />
2- 后面的代码-itemstyle 通常在pageload的init()方法中
2- code behind - itemstyle usually in a init() method on pageload
grvShowhistory.HeaderStyle.CssClass = "lnknew";
grvShowhistory.RowStyle.CssClass = "lnknew";
3- 后面的代码-itemdatabound (确保在设计器页面中具有itemdataboud方法
3- code behind - itemdatabound (make sure to have an itemdataboud method in the designer page
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- 代码落后-免费代码
4- code behind - free code
foreach (GridViewRow row in grvShowhistory.Rows)
{
row.CssClass = "lnknew";
}
这将是
this will be
<table>
<tr class="lnknew">
<td>
</td>
...
如果您需要设置TD元素的样式,则必须与该行中的元素进行匹配
再见
if you need to style the TD element you have to do match the element in the row
bye
请参阅本文
http://atashbahar.com/post/GridView-makeover-using-CSS.aspx [ ^ ]
Refer this article
http://atashbahar.com/post/GridView-makeover-using-CSS.aspx[^]
您好,
您可以通过这种方式在gridview中应用:
hello,
you can apply in this way in gridview:
<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. :)
这篇关于如何将CSS应用于gridview的行样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!