我想在网格中有3行,然后是将第3行与第4行分开的粗线,然后是3行,然后是将第6行与第7行分开的较粗的线,等等。在ASP.NET GridView控件中,每3行厚的网格线?
什么是最好的方法来做到这一点?
即。
Row 1
Row 2
Row 3
-------------
Row 4
Row 5
Row 6
-------------
我想在网格中有3行,然后是将第3行与第4行分开的粗线,然后是3行,然后是将第6行与第7行分开的较粗的线,等等。在ASP.NET GridView控件中,每3行厚的网格线?
什么是最好的方法来做到这一点?
即。
Row 1
Row 2
Row 3
-------------
Row 4
Row 5
Row 6
-------------
这样的事情应该工作。
代码隐藏:
private int RowCount { get; set; }
protected void myGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
switch(e.Row.RowType)
{
case DataControLRowType.Header:
{
RowCount = 0;
}
break;
case DataControlRowType.DataRow:
{
RowCount += 1;
if (RowCount == 3)
{
e.Row.CssClass = "BorderRow";
RowCount = 0;
}
}
break;
}
}
的CSS:
tr.BorderRow td { border-bottom: 3px solid #000000; }
这里是一个jQuery例如:
$(document).ready(function() {
$("table.MarkRows tr:nth-child(3)").addClass("BorderRow");
});
每个<table class="MarkRows">
或<asp:GridView CssClass="MarkRows" />
应该工作,假设你有我在列出的CSS规则我的.NET解决方案。
基于chprpipr的答案,这里是使用模和e.Row.RowIndex更紧凑的解决方案:
if (e.Row.RowType = DataControlRowType.DataRow)
{
if ((e.Row.RowIndex + 1) % 3 == 0)
{
e.Row.CssClass = "BorderRow";
}
}
通过与“5%”代替“%3”例如,您将添加BorderRow CSS类每5行而不是3个。
所以没有办法只用CSS或jQuery来做到这一点?我真的必须修改我的应用程序中的所有网格? – 2011-01-13 19:11:28
它可能使用JavaScript来做到这一点,但如果你对页眉,页脚或分页行做任何事情,它会使通用的JavaScript解决方案变得更加困难。你使用任何JS库(jQuery,原型等)? – chprpipr 2011-01-13 19:42:34