如何在ASP.NET中的gridview中为每个标题列添加标题

时间:2012-05-23 18:51:02

标签: asp.net visual-studio-2010 gridview tooltip

我正在使用ASP.NET,我有一个gridview,我需要在每个标题列中添加一个标题,标题将显示在moseover上.................. ...............我必须将字段转换为TemplateField

有些事情是这样的:

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

这是我的网格:

 <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 个答案:

答案 0 :(得分:1)

我认为在ASP.NET中没有办法,但你总是可以在CSS中使用HeaderStyle-CssClass在你的模板上。

更新:

好吧,我错了,ASP.NET确实支持这个功能,你只需要在TemplateField中使用HeaderTemplate。

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