how to add title for every header column in gridvi

2019-02-27 23:22发布

问题:

i'm using ASP.NET , i have a gridview and i need to put a title in every header column , title will show on moseover ................................. do i have to convert the field to TemplateField

some thing like this :

 <asp:BoundField DataField="ID_Dossier" HeaderText="ID_Dossier" ReadOnly="True" 
  SortExpression="ID_Dossier" title="Trier par identifiant des dossiers " />

this is my gridbiew :

 <asp:GridView ID="DossierGV" runat="server" AllowPaging="True" 
                            AllowSorting="True" DataSourceID="DossierPF" AutoGenerateColumns="False" 
                            DataKeyNames="ID_Dossier">
                          <Columns>
                              <asp:TemplateField ShowHeader="False" >
                                  <ItemTemplate>
                                      <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                                          CommandName="Select" Text="Ajouter" title="Ajouter les information de finance aux ce dossier"></asp:LinkButton>
                                  </ItemTemplate>
                              </asp:TemplateField>
                              <asp:BoundField DataField="ID_Dossier" HeaderText="ID_Dossier" ReadOnly="True" 
                                  SortExpression="ID_Dossier" title="Trier par identifiant des dossiers " />
                              <asp:BoundField DataField="ID_Entreprise" HeaderText="ID_Entreprise"  
                                  SortExpression="ID_Entreprise" />
                              <asp:BoundField DataField="Date_Depot" HeaderText="Date_Depot" 
                                  SortExpression="Date_Depot"  />
                              <asp:BoundField DataField="Type_Etude" HeaderText="Type_Etude" 
                                  SortExpression="Type_Etude" />
                              <asp:BoundField DataField="Dernier_Type" HeaderText="Dernier_Type" 
                                  SortExpression="Dernier_Type"  />
                              <asp:BoundField DataField="Eligibile" HeaderText="Eligibile" 
                                  SortExpression="Eligibile" />
                              <asp:BoundField DataField="Fiche_Information" HeaderText="Fiche_Information" 
                                   />
                              <asp:BoundField DataField="Buletin_Adhesion" HeaderText="Buletin_Adhesion" 
                                   />
                              <asp:BoundField DataField="Fiche_Renseignment" HeaderText="Fiche_Renseignment" 
                                   />
                              <asp:BoundField DataField="Attestation" HeaderText="Attestation" 
                                  />
                              <asp:BoundField DataField="ID_Cabinet" HeaderText="ID_Cabinet" 
                                  SortExpression="ID_Cabinet"  />
                              <asp:BoundField DataField="Montant_Demander" HeaderText="Montant_Demander" 
                                  SortExpression="Montant_Demander" />
                              <asp:BoundField DataField="Duree" HeaderText="Duree" SortExpression="Duree" />
                              <asp:BoundField DataField="Porcentage_Taux" HeaderText="Porcentage_Taux" 
                                  SortExpression="Porcentage_Taux" />
                              <asp:BoundField DataField="Nom_Giac" HeaderText="Nom_Giac" 
                                  SortExpression="Nom_Giac" />
                          </Columns>
                      </asp:GridView>

回答1:

I don't think there is a way in ASP.NET, but you can always do it in CSS just use HeaderStyle-CssClass on your template.

UPDATE:

Ok, I was wrong, ASP.NET does support this functionality, you just need use a HeaderTemplate in your TemplateField.

<asp:TemplateField SortExpression="Subnet" HeaderText="Subnet">
   <HeaderTemplate>
       <asp:Label ID="SubnetHeader" ToolTip="My Tip to you" runat="server" Text="Label"></asp:Label>
   </HeaderTemplate>

   <ItemTemplate >  
       <asp:Label ID="lblSubnet" runat="server" Text='<%# Bind("Subnet") %>' ></asp:Label>       
   </ItemTemplate>
</asp:TemplateField>