我有一个动态的GridView1,其AutogenerateFields设置为TRUE。以下代码将在GridView中显示单元格的值,但是我需要做的是将鼠标悬停在单元格上时显示列名。任何帮助表示赞赏。谢谢!
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
for (int i = 0; i < GridView1.Columns.Count; i++)
{
e.Row.Cells[i].ToolTip = GridView1.Columns[i].HeaderText;
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (TableCell gvcell in e.Row.Cells)
{
gvcell.ToolTip = gvcell.Text;
}
}
}
使用此代码段。您可以循环处理OnRowDataBound
事件中的所有单元格,并从中获取标题文本HeaderRow
。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//check if the row is a datarow
if (e.Row.RowType == DataControlRowType.DataRow)
{
//loop all cells in the row
for (int i = 0; i < e.Row.Cells.Count; i++)
{
//set the tooltip text to be the header text
e.Row.Cells[i].ToolTip = GridView1.HeaderRow.Cells[i].Text;
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句