Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have to show template field where I can use sort expression and I have to use header template where I have to show textbox
My problem is that both are not showing together.When I place header template template field header text disappeared.i don't know why it is happening.

What I have tried:

ASP.NET
 <asp:GridView ID="GridViewemp" runat="server" AllowPaging="True" class="gv"
            AllowSorting="True" onpageindexchanging="GridViewemp_PageIndexChanging" 
            BorderColor="#3399FF" BorderStyle="Groove" 
            CellPadding="1" CellSpacing="1"
            onsorting="GridViewemp_Sorting" PageSize="5" AutoGenerateColumns="False" 
            Height="10px" onselectedindexchanged="GridViewemp_SelectedIndexChanged">
            <Columns>
             <asp:TemplateField HeaderText="E_Id ●" ControlStyle-Font-Names="Arial" SortExpression="eid" >
            <ItemTemplate>
           <asp:Label ID="lblid" runat="server" Text='<%#Eval("eid")%>'/>
           </ItemTemplate>
<ControlStyle Font-Names="Arial"></ControlStyle>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="E_Name ●" SortExpression="ename" ShowHeader="true" >
            <HeaderTemplate>
            <table>
          <tr><td></td></tr>
          <tr><td> <cc1:ComboBox ID="ComboBoxname" runat="server" AutoCompleteMode="SuggestAppend" DropDownStyle="Simple" Width="50px">
              </cc1:ComboBox></td>
          </tr>
          </table>
            </HeaderTemplate>

            <ItemTemplate>
           <asp:Label ID="lblname" runat="server" Text='<%#Eval("ename")%>' />
           </ItemTemplate>
          </asp:TemplateField>
          <                                                <asp:TemplateField HeaderText="E_Group ●" SortExpression="egrp">
           <ItemTemplate>
           <asp:Label ID="lblgrp" runat="server" Text='<%#Eval("egrp")%>'/>
           </ItemTemplate>
          </asp:TemplateField>
          				
</Columns>
            <HeaderStyle Font-Names="Times New Roman" Font-Size="Small" 
                ForeColor="Black" CssClass="header" Wrap="False" />
        </asp:GridView>
Posted
Updated 14-Nov-16 19:09pm

1 solution

First you need to understand what a HeaderTemplate is. Check below link-
Quote:
Use the HeaderTemplate property to specify the custom content displayed for the header section of a TemplateField object. Define the content by creating a template that specifies how the header section is rendered.

TemplateField.HeaderTemplate Property (System.Web.UI.WebControls)[^]

You have also defined HeaderText in the template field-
HTML
HeaderText="E_Name ●"

It's not possible to show the content of HeaderTemplate and HeaderText at the same time.

So, what you can do is, change the HeaderTemplate accordingly to accomodate the HeaderText. Something like-
HTML
<headertemplate>
<table>
      <tr><td>E_Name ●</td></tr>


Hope, it helps :)
 
Share this answer
 
v3
Comments
Pragya Nagwanshi 15-Nov-16 1:17am    
and how I will perfrom sorting based on sort expression
Pragya Nagwanshi 15-Nov-16 1:21am    
Actully based on sort expression I am changing header text dynamically.so how I will be able to change header text or reflect to header template column value

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900