我有一个gridView: -
<asp:GridView ID="gvwAccums" runat="server"
AutoGenerateColumns="false"
CssClass="GridView"
HeaderStyle-CssClass="GridViewHeaderRowStyle"
RowStyle-CssClass="GridViewRowStyle"
AlternatingRowStyle-CssClass="GridViewAlternatingRowStyle"
EmptyDataRowStyle-CssClass="GridEmptyDataRowStyle"
>
<Columns>
<asp:BoundField HeaderText="Start Date" DataField="Beg_PlanYr" />
<asp:BoundField HeaderText="Paid" DataField="indTotPaid" DataFormatString="{0:F}" HeaderStyle-HorizontalAlign="Right"
ItemStyle-HorizontalAlign="Right" />
<asp:BoundField HeaderText="Copay" DataField="indTotCopay" DataFormatString="{0:F}" HeaderStyle-HorizontalAlign="Right"
ItemStyle-HorizontalAlign="Right" />
<asp:BoundField HeaderText="Deductible" DataField="indTotDed" DataFormatString="{0:F}" HeaderStyle-HorizontalAlign="Right"
ItemStyle-HorizontalAlign="Right" />
<asp:BoundField HeaderText="Out of Pocket" DataField="indTotOop" DataFormatString="{0:F}" HeaderStyle-HorizontalAlign="Right"
ItemStyle-HorizontalAlign="Right" />
</Columns>
<EmptyDataTemplate>
<div id="pnlEmptyAcums" runat="server" class="NoRecs">
<span style="font-style: italic">No Accumulated Totals found.</span>
</div>
</EmptyDataTemplate>
</asp:GridView>
我试图在服务器端的列标题中添加定义文本: -
protected void gvwAccums_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
bool isDataRow = row.RowType == DataControlRowType.DataRow;
TableCellCollection cells = e.Row.Cells;
string allCells = string.Empty;
string content = "";
int lastCol = cells.Count - 1;
content = cells[lastCol].Text.Trim();
// Only do this to the header row, ignore data and footer rows. Adding definition to the label of each column on the Gridview of claims.
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].ToolTip = "xxxxx ";
e.Row.Cells[1].ToolTip = "yyyyy ";
e.Row.Cells[2].ToolTip = "zzzzz ";
e.Row.Cells[3].ToolTip = "fffff ";
e.Row.Cells[4].ToolTip = "vvvvv ";
}
}
但是当我用鼠标指针悬停时,我看不到任何文字。 gridview本身工作正常。
有人可以帮忙吗?
答案 0 :(得分:3)
您的代码适用于我 - 当鼠标悬停在标题文本上时显示工具提示。
如果仍然无效,您可以尝试使用Attributes.Add
e.Row.Cells[0].Attributes.Add("title", "xxxxx ");
public class Test
{
public int Beg_PlanYr { get; set; }
public decimal indTotPaid { get; set; }
public decimal indTotCopay { get; set; }
public decimal indTotDed { get; set; }
public decimal indTotOop { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gvwAccums.DataSource = new List<Test>()
{
new Test {Beg_PlanYr = 1, indTotPaid = 1, indTotCopay = 1, indTotDed = 1, indTotOop = 1},
new Test {Beg_PlanYr = 2, indTotPaid = 2, indTotCopay = 2, indTotDed = 2, indTotOop = 2},
new Test {Beg_PlanYr = 3, indTotPaid = 3, indTotCopay = 3, indTotDed = 3, indTotOop = 3},
};
gvwAccums.DataBind();
}
}
protected void gvwAccums_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].ToolTip = "xxxxx ";
e.Row.Cells[1].ToolTip = "yyyyy ";
e.Row.Cells[2].ToolTip = "zzzzz ";
e.Row.Cells[3].ToolTip = "fffff ";
e.Row.Cells[4].ToolTip = "vvvvv ";
}
}