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

半腔热情 提交于 2019-12-07 17:31:55

问题


I have the following code ...

<asp:DetailsView ID="dvApprenticeship" runat="server" DataSourceID="dsApprenticeship" AutoGenerateRows="false" BackColor="#E0E8F0" GridLines="None" CellPadding="2"
    DataKeyNames="ProgramID, ProgramName, OrganisationName, StudyYearID, Workgroup, Pathway, FinishDate" OnDataBound="Apprenticeship_DataBound">
    <Fields>
        <asp:BoundField DataField="ProgramName" HeaderText="Program:" />
        <asp:BoundField DataField="StudyYearName" HeaderText="Study Year:" />
        <asp:HyperLinkField DataTextField="OrganisationName" HeaderText="Apprenticeship:&nbsp;" NavigateUrl="Apprenticeships.aspx" />
        <asp:BoundField DataField="Workgroup" HeaderText="Workgroup:" />
        <asp:BoundField DataField="Pathway" HeaderText="Pathway:" />
        <asp:TemplateField HeaderText="Nominal Completion:&nbsp;">
            <ItemTemplate>
                <asp:Label ID="labEndDate" runat="server" Text='<%# Eval("FinishDate","{0:d/MM/yyyy}") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Fields>
    <FooterTemplate>
        <asp:LinkButton ID="lbAddProgramUnits" runat="server" OnClick="AddProgramUnits_Click" ForeColor="White" Font-Bold="true"
            OnClientClick="return confirm('Import the Program Units listed - this may overwrite unit dates. Are you sure?');">Import from Program</asp:LinkButton>&nbsp;&nbsp;
        <a href="#" onclick="showhelp('progimphelp');" style="color:White;font-weight:bold;">Help</a>
    </FooterTemplate>
    <FooterStyle HorizontalAlign="Center" BackColor="LightSlateGray" />
</asp:DetailsView>

I want to be able to show a tooltip whenever one of the above Boundfields has changed color.

In my C# codebehind, I have code that changes the color of these boundfields depending on certain conditions of the data. This is working fine.

But what I want is to be able to give the users a tooltip when ever they hover their mouse over these Boundfields and ONLY if that field is coloured differently, in my case

color.Yellow

.


回答1:


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";



回答2:


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.



来源:https://stackoverflow.com/questions/20647967/how-to-add-a-tooltip-to-boundfields-in-a-detailsview-but-only-if-color-of-colum

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