C# 在gridview单元格工具提示ASP.net/C中显示列的名称#
我有一个动态GridView1,其中AutogenerateFields设置为TRUE。下面的代码将在GridView中显示单元格的值,但我需要它做的是在将鼠标悬停在单元格上时显示列名。感谢您的帮助。谢谢C# 在gridview单元格工具提示ASP.net/C中显示列的名称#,c#,asp.net,C#,Asp.net,我有一个动态GridView1,其中AutogenerateFields设置为TRUE。下面的代码将在GridView中显示单元格的值,但我需要它做的是在将鼠标悬停在单元格上时显示列名。感谢您的帮助。谢谢 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { fo
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;
}
}
}
受保护的无效GridView1\u行数据绑定(对象发送方,GridViewRowEventArgs e)
{
if(e.Row.RowType==DataControlRowType.Header)
{
对于(int i=0;i
这很简单,我想知道为什么在列名为headertext.bdw时要显示工具提示
<asp:TemplateField HeaderText="Category">
<ItemTemplate>
<asp:Label runat="server" ToolTip="Category" ID="lblCategory" Text='<%#Eval("Category") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sub Category">
<ItemTemplate>
<asp:Label runat="server" ToolTip="SubCategory" ID="lblSubCategory" Text='<%#Eval("SubCategory") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
这很简单,我想知道为什么在列名为headertext.bdw时要显示工具提示
<asp:TemplateField HeaderText="Category">
<ItemTemplate>
<asp:Label runat="server" ToolTip="Category" ID="lblCategory" Text='<%#Eval("Category") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sub Category">
<ItemTemplate>
<asp:Label runat="server" ToolTip="SubCategory" ID="lblSubCategory" Text='<%#Eval("SubCategory") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
使用此代码段。您可以循环
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;
}
}
}
受保护的无效GridView1\u行数据绑定(对象发送方,GridViewRowEventArgs e)
{
//检查该行是否为datarow
如果(e.Row.RowType==DataControlRowType.DataRow)
{
//循环行中的所有单元格
for(int i=0;i
使用此代码段。您可以循环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;
}
}
}
受保护的无效GridView1\u行数据绑定(对象发送方,GridViewRowEventArgs e)
{
//检查该行是否为datarow
如果(e.Row.RowType==DataControlRowType.DataRow)
{
//循环行中的所有单元格
for(int i=0;i
我刚刚更新了代码。我有一个错误。我刚刚更新了代码。我有一个错误。我有从存储过程生成的未知数量的列。我想知道是否有一种C#方式可以在工具提示中显示列名。我不想硬编码列名称,因为存储过程生成的列数量未知。我想知道是否有一种C#方式可以在工具提示中显示列名。我不想硬编码列名称快速问题VDWWD,我如何在工具提示中引用ColumnName:RowName?您的意思是这样的<代码>e.Row.Cells[i]。工具提示=GridView1.HeaderRow.Cells[i]。文本+“:行+i不确定您所说的RowName
到底是什么意思,除了e.Row.Cells[i]。Text我使用了e.Row.Cells[1]。Text。非常感谢你!VDWWD,如果单元格的值为空,如何隐藏工具提示?快速问题VDWWD,如何在工具提示中引用ColumnName:RowName?您的意思是这样的<代码>e.Row.Cells[i]。工具提示=GridView1.HeaderRow.Cells[i]。文本+“:行+i不确定您所说的RowName
到底是什么意思,除了e.Row.Cells[i]。Text我使用了e.Row.Cells[1]。Text。非常感谢你!VDWWD,如果单元格的值为空,如何隐藏工具提示?