The error message is pretty self-explanatory - the
ItemTemplate
for
a TemplateField
field[
^] doesn't contain properties called
CommandName
or
CommandArgument
. It's just a placeholder for whatever you want to appear in that column.
If you want the values in the column to be clickable, then you'll need to add a
Button
or
LinkButton
to the template:
<asp:TemplateField ...>
<ItemTemplate>
<asp:Button runat="server"
CommandName="Sort"
CommandArgument="myDBfield"
Text='<%# Container.DataItemIndex + 1 %>'
/>
</ItemTemplate>
</asp:TemplateField>
If you want the column to be sortable, then set the
SortExpression
property on the
TemplateField
:
<asp:TemplateField ... SortExpression="myDBfield">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>