我有一个 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 本身工作正常。
有人能帮忙吗?
最佳答案
您的代码对我有用 - 当鼠标悬停在标题文本上时会显示工具提示。
如果还是不行,你可以试试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 ";
}
}
关于c# - 带有鼠标悬停的列标题的 gridView 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20253945/