我正在向GridView添加工具提示,并且正在运行一个有趣的错误。当我有用于填充我的工具提示可见的绑定字段时,一切正常。当它被隐藏时,工具提示是空白的(我预期,因为隐藏时不会发送数据)。为了解决这个问题,我使用DataKeyNames属性来保存数据。添加它时,会导致Resources.ExceptionPolicyNotFound异常。
这是网格视图(有拒绝原因):
<asp:GridView ID="GrdSearchResult" runat="server" AutoGenerateColumns="False" OnRowDataBound="GrdSearchResult_RowDataBound"
Width="100%" AllowPaging="True" OnPageIndexChanging="GrdSearchResult_PageIndexChanging"
EmptyDataText="No record found." PageSize="20" CssClass="GridStyle" PagerStyle-CssClass="PagerStyle" EmptyDataRowStyle-CssClass="EmptyStyle"
DataKeyNames="RejectReason">
<Columns>
<asp:BoundField HeaderText="Reject Code" DataField="RejectCode"/>
<asp:BoundField HeaderText="Claim #" DataField="ClaimNbr" />
<asp:BoundField HeaderText="Member Medicaid #" DataField="MemberMedicaidNbr" />
<asp:BoundField HeaderText="Member Name" DataField="MemberName" />
<asp:BoundField HeaderText="Provider Name" DataField="ProviderName" />
<asp:BoundField HeaderText="Check(s) Details" />
<asp:BoundField HeaderText="Date of Service" DataFormatString="{0:MM-dd-yyyy}" DataField="ServiceRange" />
<asp:BoundField HeaderText="Claims Link" />
<asp:BoundField HeaderText="RejectReason" DataField="RejectReason" Visible="false" />
</Columns>
</asp:GridView>
这是使用该列的代码,但它在错误之前永远不会被命中。
e.Row.Cells[0].ToolTip = e.Row.Cells[8].Text.ToString();
目标是将第一列的工具提示设置为最后一列(第9列)的值。
答案 0 :(得分:0)
我仍然不确定导致错误的原因,但我已经决定以不同的方式解决这个问题。我没有隐藏数据字段,而是在设置工具提示后隐藏它。
e.Row.Cells[0].ToolTip = e.Row.Cells[8].Text.ToString();
e.Row.Cells[8].Visible = false;
唯一的缺点就是隐藏了列标题,但我在另一个部分用相同的代码管理了它。现有代码使用
if (e.Row.Cells[0].Text != string.Empty)
要仅查看数据行而不是标题行,所以我添加了。
else
{
e.Row.Cells[8].Visible = false;
}
完成数据操作后。