[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP.NET Gridview Question

Posted on 2014-08-14
2
Medium Priority
?
25 Views
Last Modified: 2016-06-21
I have the below column in a gridview control . I need to put different buttons in the column based on what state the gridview is in . However, right now I cannot seem to make the CommandField show up. I want to show the CommandField  if the gridview row is simply in display mode.  I am using the FooterTemplate  for data entry and the  EditTemplate for editing. How do I display the CommandField in the same column w/o the other buttons if the row is in display mode. Any help would be greatly appreciated.
										
<asp:TemplateField HeaderText="">
   <ItemTemplate>
      <asp:CommandField ValidationGroup="InsertHeUnitValEDIT" CausesValidation="true"  DeleteText="Delete"     EditText="Edit"  CancelText="Cancel" ShowCancelButton="true" ShowDeleteButton="true" ShowEditButton="true" ShowSelectButton="false" />
</ItemTemplate>

 <EditItemTemplate>
      <asp:Button ID="btnGetCorrespondingValuesEDIT" Visible="true" style="font-size: 6pt; width: 56px;" runat="server" Text="Get Values" OnClick="btnGetCorrespondingValuesEDIT_OnClick" Width="50px" Height="20px" />
</EditItemTemplate>

<FooterTemplate>
  <br />
<asp:Button ID="btnInsert" runat="Server" Text="Insert" style="font-size: 8pt; width: 56px;" CausesValidation="true" ValidationGroup="InsertHeUnitValFT" CommandName="Insert" UseSubmitBehavior="False" />
<br />
<asp:Button ID="btnCancelUnit" runat="Server" Text="Cancel" style="font-size: 8pt; width: 56px;" CausesValidation="false" ValidationGroup="InsertHeUnitValFT" CommandName="Cancel" UseSubmitBehavior="False" />
<br />
 <asp:Button ID="btnGetCorrespondingValues" Visible="true" runat="server" style="font-size: 6pt; width: 56px;" Text="Get Values" OnClick="btnGetCorrespondingValues_OnClick" />
</FooterTemplate>
                                             
</asp:TemplateField>

Open in new window

0
Comment
Question by:jazzcatone
1 Comment
 
LVL 21

Accepted Solution

by:
MogalManic earned 2000 total points
ID: 40263885
The ASP:Command field cannot be used in a template.  You can either do something like this:
        <Columns>
            <asp:CommandField ValidationGroup="InsertHeUnitValEDIT" CausesValidation="true"  DeleteText="Delete"  ShowDeleteButton="true" EditText="" ShowEditButton="true" />

Open in new window


or in a template field, manually create buttons:
        <Columns>
            <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                        CommandName="Edit" Text=""></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Delete" Text="Delete"></asp:LinkButton>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                        CommandName="Update" Text="Update"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                </EditItemTemplate>
            </asp:TemplateField>

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question