2013-12-18 26 views
3

我有以下代碼...如何將工具提示添加到綁定列在一個DetailsView,但只有當列的顏色已經改變

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

我希望能夠顯示工具提示時的一個Boundfields上面已經改變了顏色。

在我的C#代碼隱藏中,我有代碼根據數據的某些條件更改這些綁定字段的顏色。這工作正常。

但我想要的是能夠給用戶一個提示當過他們將其鼠標在這些綁定列且僅當此場不同的着色,在我的情況

color.Yellow

回答

1

如果您是在基於一些標準在DetailsView DataBound事件的顏色設置爲黃色,您可以設置提示在同一個塊:

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

謝謝!一些如此簡單。我不知道這個屬性。 – Fandango68

+0

我知道這是一箇舊的帖子,但有沒有辦法將css添加到工具提示, – JustLearning

+2

@CosmosBanda搜索網站或單獨提出您的問題......我們並沒有真正回答評論中的無關問題以回答一個不同的問題。 – ethorn10

3

並回答我的問題,別的東西我發現,這被忽略了:將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的設計模式下,你可以選擇你的DetailsView控件,選擇編輯字段選項,然後選擇是BoundFields的字段並將它們直接轉換爲TemplateFields。它的優點在於它將BoundFields轉換爲整齊的標籤或文本框,允許您直接在ToolTip屬性中進行編碼!沒有代碼背後!微軟曾經在那裏做過一次。

相關問題