/// <summary>
/// OnRowDataBound
/// </summary>
/// <param name="e"></param>
protected override void OnRowDataBound(GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager)
{
if (FixRowCol.IsFixPager)
{
if ( this.PagerSettings.Position == PagerPosition.Top || ( this.PagerSettings.Position == PagerPosition.TopAndBottom && _isTopPager))
{
// TopPager固定行和列
e.Row.Cells[0].Attributes.Add( "style", "z-index:999; position: relative; top: expression(this.offsetParent.scrollTop); left: expression(this.offsetParent.scrollLeft);");
// 现在是TopPager,之后就是BottomPager了,所以设置_isTopPager为false
_isTopPager = false;
}
else if ( this.PagerSettings.Position == PagerPosition.TopAndBottom && !_isTopPager)
{
// BottomPager只固定列
e.Row.Cells[0].Attributes.Add( "style", "z-index:999; position: relative; left: expression(this.offsetParent.scrollLeft);");
// 现在是BottomPager,之后就是TopPager了,所以设置_isTopPager为true
_isTopPager = true;
}
}
}
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
// 给每一个指定固定的列的单元格加上css属性
if (!String.IsNullOrEmpty(FixRowCol.FixColumnIndices))
{
// 列索引
foreach ( string s in FixRowCol.FixColumnIndices.Split(','))
{
int i;
if (!Int32.TryParse(s, out i))
throw new ArgumentException( "FixColumnIndices", "含有非整形的字符");
if (i > e.Row.Cells.Count)
throw new ArgumentOutOfRangeException( "FixColumnIndices", "溢出");
e.Row.Cells[i].Attributes.Add( "style", "position: relative; left: expression(this.offsetParent.scrollLeft);");
}
}
bool isFixRow = false; // 当前行是否固定
if (FixRowCol.IsFixHeader && e.Row.RowType == DataControlRowType.Header)
{
isFixRow = true;
}
if (!String.IsNullOrEmpty(FixRowCol.FixRowIndices) && e.Row.RowType == DataControlRowType.DataRow)
{
// 行索引
foreach ( string s in FixRowCol.FixRowIndices.Split(','))
{
int i;
if (!Int32.TryParse(s, out i))
throw new ArgumentException( "FixRowIndices", "含有非整形的字符");
if (i > e.Row.Cells.Count)
throw new ArgumentOutOfRangeException( "FixRowIndices", "溢出");
if (i == e.Row.RowIndex)
{
isFixRow = true;
break;
}
}
}
// 固定该行
if (isFixRow)
{
// 该行的每一个单元格
for ( int j = 0; j < e.Row.Cells.Count; j++)
{
// 该单元格不属于固定列
if (String.IsNullOrEmpty(e.Row.Cells[j].Attributes[ "style"]) || e.Row.Cells[j].Attributes[ "style"].IndexOf( "position: relative;") == -1)
{
e.Row.Cells[j].Attributes.Add( "style", " position: relative; top: expression(this.offsetParent.scrollTop);");
}
// 该单元格属于固定列
else
{
e.Row.Cells[j].Attributes.Add( "style", e.Row.Cells[j].Attributes[ "style"] + "top: expression(this.offsetParent.scrollTop); z-index: 666;");
}
}
}
}
base.OnRowDataBound(e);
}