我有以下代码...
<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: " NavigateUrl="Apprenticeships.aspx" />
<asp:BoundField DataField="Workgroup" HeaderText="Workgroup:" />
<asp:BoundField DataField="Pathway" HeaderText="Pathway:" />
<asp:TemplateField HeaderText="Nominal Completion: ">
<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>
<a href="#" onclick="showhelp('progimphelp');" style="color:White;font-weight:bold;">Help</a>
</FooterTemplate>
<FooterStyle HorizontalAlign="Center" BackColor="LightSlateGray" />
</asp:DetailsView>
我希望能够在上述边界字段之一更改颜色时显示工具提示。
在我的 C# 代码隐藏中,我有一些代码可以根据数据的某些条件更改这些边界字段的颜色。这工作正常。
但我想要的是,当用户将鼠标悬停在这些边界字段上时,能够为用户提供工具提示,并且仅当该字段的颜色不同时,在我的例子中
颜色.黄色
.
为了回答我自己的问题,我发现了一些被忽视的东西:将 BoundField 转换为 TemplateField 选项。
由此 ...
<asp:BoundField HeaderText="Claim Type ID" ..etc../>
对此...
<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>
这很不错,因为在 ASPX 的设计模式中,您可以选择“详细信息视图”,选择“编辑字段”选项,然后选择作为 BoundFields 的字段,然后将它们直接转换为 TemplateFields。这样做的好处是,它将 BoundFields 转换为整洁的标签或文本框,允许您直接在 ToolTip 属性中进行编码!并且后面没有代码!微软这一次做到了这一点。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)