Click here to Skip to main content
16,015,921 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I tried adding comandname but it does not work
I am asking again as previous question unanswered

What I have tried:

ASP.NET
<asp:TemplateField  HeaderText='<img width="20px" height="20px" src="../Images/updown.png"/>Id'  ItemStyle-HorizontalAlign="Center"  >
    <itemtemplate commandname="Sort" commandargument="myDBfield"><%#Container.DataItemIndex+1%></itemtemplate>
    
                   
    <asp:BoundField HtmlEncode="false" DataField="LoanType" HeaderText='<img  src="../Images/updown.png"/>LoanType' SortExpression="LoanType" />
    <asp:BoundField DataField="LoanTerm" HeaderText="Term(Years)" SortExpression="LoanTerm" />
    <asp:BoundField DataField="LoanRate" HeaderText="LoanRate" SortExpression="LoanRate" />
    <asp:BoundField DataField="LoanAvailableFrom" HeaderText="Loan Available From" SortExpression="LoanAvailableFrom" />
    <asp:BoundField DataField="LoanAvailableTo" HeaderText="Loan Available To" SortExpression="LoanAvailableTo" />
    <asp:CommandField HeaderText="Edit" SelectText="Edit" ShowSelectButton="True" />
    <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ShowHeader="True" />
Posted
Updated 29-Jul-16 4:43am
v2

1 solution

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.NET
<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.NET
<asp:TemplateField  ... SortExpression="myDBfield">
    <ItemTemplate>
        <%# Container.DataItemIndex + 1 %>
    </ItemTemplate>
</asp:TemplateField>
 
Share this answer
 
Comments
Suvendu Shekhar Giri 29-Jul-16 11:02am    
My 5!

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