GridView技巧收集
1.高亮显示GridView当前行
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='yellow',this.style.fontWeight='bold'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white',this.style.fontWeight=''");
}
}
或{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='yellow',this.style.fontWeight='bold'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white',this.style.fontWeight=''");
}
}
/// <summary>
/// 使GridView实现onMouseOver加亮的方法,需要将方法加在RowDataBound事件中。
/// </summary>
/// <param name="e">GridViewRowEventArgs</param>
public static void GridViewStyle(GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.className='tdbgmouseover'");
e.Row.Attributes.Add("onmouseout", "this.className='tdbg'");
}
}
/// 使GridView实现onMouseOver加亮的方法,需要将方法加在RowDataBound事件中。
/// </summary>
/// <param name="e">GridViewRowEventArgs</param>
public static void GridViewStyle(GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.className='tdbgmouseover'");
e.Row.Attributes.Add("onmouseout", "this.className='tdbg'");
}
}