Leon
Leon

Reputation: 581

How to enable sorting on an ItemTemplate column of checkboxes in the .aspx page?

This is how I have it in the .aspx page:

<asp: TemplateField HeaderText="Hide/Show" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
        <asp:CheckBox ID="HideShowChk" runat="server" Checked='<%# Bind("Hide_Show") %>' />
    </ItemTemplate>
<asp: TemplateField>

This is how the TemplateField is like in Griview. How do I enable sorting on this since the "Enable Sorting" checkbox in Visual Studio doesn't enable it for this column.

Note, I have absolutely no code in the code behind.

Upvotes: 1

Views: 551

Answers (1)

Kirk
Kirk

Reputation: 16255

Use the SortExpression property within the TemplateField

<asp:TemplateField HeaderText="Hide/Show" ItemStyle-HorizontalAlign="Center" SortExpression="Hide_Show">
    <ItemTemplate>
        <asp:CheckBox ID="HideShowChk" runat="server" Checked='<%# Bind("Hide_Show") %>' />
    </ItemTemplate>
<asp:TemplateField>

Upvotes: 1

Related Questions