Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When I am clicking the gridview edit button from ItemTemplate of TemplateField it is not showing me the update and cancel buttons from EditItemTemplate of TemplateField.

Actually what is happening is when i click the edit button it refreshes the gridview and finally the data is binded again but the update and cancel buttons are not appearing at all can anyone tell me where is the exact problem.

What I have tried:

<asp:TemplateField ItemStyle-Width="30px" ItemStyle-Wrap="false">
    <ItemTemplate>
        <asp:Button ID="btnEdit" runat="server" Text="Edit" CssClass="btn btn-link text-center" ToolTip="edit data" CommandName="Edit" UseSubmitBehavior="false" CausesValidation="false" OnClick="btnEdit_Click" />
        <button type="button" id="btn" runat="server" disabled onserverclick="btn">
            Approve
        </button>
    </ItemTemplate>
    <EditItemTemplate>
        <asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" CssClass="btn btn-link" UseSubmitBehavior="false" />
        <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" CssClass="btn btn-link" UseSubmitBehavior="false" />
    </EditItemTemplate>                                            
</asp:TemplateField>
Posted
Updated 8-Apr-18 22:56pm
Comments
[no name] 6-Apr-18 8:09am    
Do you see other data is properly bound to your grid control? Can you add that code as well
Member 8583441 9-Apr-18 0:47am    
sorry for the late reply sir. Actually what is going on is gridview is collapsing and again come back into normal but the button are not displayed update and cancel in edititemtemplate field
Member 8583441 9-Apr-18 2:16am    
If the EnableViewState=false then postbacking the data and remains same.
When EnableViewState=true then getting error "Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request."

<asp:TemplateField HeaderStyle-Font-Bold="false" HeaderStyle-Font-Size="12px" HeaderText="Print" ItemStyle-Font-Bold="false" ItemStyle-Font-Size="12px" ItemStyle-Width="20px">
                       <ItemTemplate>
                           <asp:Button ID="butprint" runat="server" Text="Print" BackColor="Green" CommandName="Print" ForeColor="White" Width="50px" />
                       </ItemTemplate>
                       <HeaderStyle Font-Bold="True" Font-Size="12px" />
                       <ItemStyle Font-Bold="False" Font-Size="12px" Width="20px" />
                   </asp:TemplateField>
 
Share this answer
 
Finally I got the solution..... Using the bind data method from code behind it is not working properly and i deleted it and added sqldatasource to bind the data from the database. Now it is working properly as expected.....

But anyone can explain me why gridview is not getting as expected when binding data from the method in the code behind.... I don't know please explain me clearly.....
 
Share this answer
 

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