How to add a tooltip to Boundfields in a Detailsview, but only if color of column has changed

浪子不回头ぞ 提交于 2019-12-06 03:23:51

If you are setting the color to yellow in the DetailsView DataBound event based on some criteria, you can set the tooltip in that same block:

DetailsViewRow.Cells[indexofyellowfield].ToolTip = "some help from code-behind";

And to answer my own question, with something else I found, which was overlooked: the convert BoundField to TemplateField option.

From this ...

<asp:BoundField HeaderText="Claim Type ID" ..etc../>

To This ...

<asp:TemplateField HeaderText="Claim Type ID">
    <EditItemTemplate>
        <asp:Label ID="lblClaimTypeID" runat="server" Text='<%# Eval("ClaimTypeID") %>' ToolTip="Enter a numerical value that conforms to the UserChoice Policy document (ie: 65 for GAT)."></asp:Label>
    </EditItemTemplate>
    <InsertItemTemplate>
        <asp:TextBox ID="txtClaimTypeID" runat="server" Text='<%# Bind("ClaimTypeID") %>' ToolTip="Enter a numerical value that conforms to the UserChoice Policy document (ie: 65 for GAT)."></asp:TextBox>
    </InsertItemTemplate>
    <ItemTemplate>
        <asp:Label ID="itClaimTypeID" runat="server" Text='<%# Bind("ClaimTypeID") %>' ToolTip="A numerical value that conforms to the UserChoice Policy document (ie: 65 for GAT)."></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

This is sweet, because in the Design mode of ASPX, you can select your DetailsView, select the Edit Fields option and select the fields that are BoundFields and convert them straight into TemplateFields. The beauty with that, is that it converts the BoundFields to neat Labels or TextBoxes allowing you to directly code in a ToolTip property! And no code behind! Microsoft got something right there for once.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!