Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I add a CheckBox to a TemplateField HEADER?

I have this:

<asp:GridView ID="gvShows" runat="server" HorizontalAlign="Center" DataKeyNames="dataSource,title" Caption="Show List" AutoGenerateColumns="False" AllowSorting="True" CaptionAlign="Top" OnSorting="gvShows_Sorting">
<RowStyle BorderColor="Black" />
<Columns> 
    <asp:TemplateField HeaderText="Select" > 
        <ItemTemplate> 
            <asp:CheckBox ID="cbSelect" runat="server" AutoPostBack="false"/> 
        </ItemTemplate> 
    </asp:TemplateField> 
    <asp:BoundField HeaderText="Data Source" DataField="DataSource" SortExpression="DataSource"/> 
    <asp:BoundField HeaderText="Show Title" DataField="Title" SortExpression="Title"/> 
    <asp:BoundField HeaderText="Episode Title" DataField="EpisodeTitle"     SortExpression="EpisodeTitle"/> 
    <asp:BoundField HeaderText="Genre" DataField="Genre" SortExpression="Genre"/> 
    <asp:BoundField HeaderText="Show Type Description" DataField="ShowTypeDescription" SortExpression="ShowTypeDescription"/> 
    <asp:BoundField HeaderText="Director Name" DataField="DirectorName" SortExpression="DirectorName"/> 
    <asp:BoundField HeaderText="Release Year" DataField="ReleaseYear" SortExpression="ReleaseYear"/> 
    <asp:BoundField HeaderText="Season Episode" DataField="SeasonEpisode" SortExpression="SeasonEpisode"/> 
    <asp:BoundField HeaderText="Show ID" DataField="ShowId" SortExpression="ShowId"/> 
    <asp:BoundField HeaderText="Episode ID" DataField="EpisodeID" SortExpression="EpisodeID"/> 
</Columns>  

Which gives me this:

I want to change where the highlighted word "SELECT" is to an actual CheckBox so that when the user checks it, it checks all boxes under.

How do I go about modifying the header text from "Select" to an actual CheckBox?

like image 518
JJ. Avatar asked Jul 08 '13 16:07

JJ.


People also ask

How do I add a check box in grid view?

From the GridView s smart tag, click on the Edit Templates link and then drag a CheckBox Web control from the Toolbox into the ItemTemplate . Set this CheckBox s ID property to ProductSelector . With the TemplateField and CheckBox Web control added, each row now includes a checkbox.


1 Answers

You can use Header Template to achieve this and remove the HeaderText from the Template field

 <asp:TemplateField > 
  <ItemTemplate> 
     <asp:CheckBox ID="cbSelect" runat="server" AutoPostBack="false"/> 
   </ItemTemplate> 

  <HeaderTemplate>
    <asp:CheckBox ID="chkBxHeader" runat="server" />
    </HeaderTemplate>
 </asp:TemplateField>  
like image 135
Sachin Avatar answered Sep 22 '22 12:09

Sachin