This is a migrated thread and some comments may be shown as answers.

Several buttons inside FormTemplate

2 Answers 38 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Roy Halvorsen
Top achievements
Rank 1
Roy Halvorsen asked on 16 Nov 2011, 09:02 AM
I have a grid with a formtemplate. The formtemplate has 4 buttons: Save (CommandName="Update"), Cancel (CommandName="Cancel"), GoToStart (OnClick="btnGoToStart_Click"), PrintToPdf (OnClick="btnPrintToPdf_Click"). As you can see 2 of the buttons perform a grid command, and 2 of the buttons has their own click events. After clicking the Save button or Cancel button, the grid does exactly what's expected. But, if I click on Save, and then click on GoToStart or PrintToPdf buttons, they do not enter theis events, but acts like the Cancel button. What am I missing here?

2 Answers, 1 is accepted

Sort by
0
Roy Halvorsen
Top achievements
Rank 1
answered on 16 Nov 2011, 09:46 AM
Never mind. I found a solution. Put e.canceled = true as the last line in the UpdateCommand event.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Nov 2011, 09:47 AM
Hello,

Please check below code snippet there is not such type of issue with Radgrid.
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
           OnItemCommand="RadGrid1_ItemCommand">
           <MasterTableView DataKeyNames="ID1" CommandItemDisplay="Top" EditMode="EditForms">
               <Columns>
                   <telerik:GridBoundColumn DataField="ID1" HeaderText="ID1" UniqueName="ID1">
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="ID2" HeaderText="ID2" UniqueName="ID2">
                   </telerik:GridBoundColumn>
                   <telerik:GridEditCommandColumn>
                   </telerik:GridEditCommandColumn>
               </Columns>
               <EditFormSettings EditFormType="Template">
                   <FormTemplate>
                       <%# Eval("ID1") %>
                       <br />
                       <asp:Button ID="Button1" runat="server" Text="Button1" OnClick="Button1_Click" />
                       <br />
                       <asp:Button ID="Button2" runat="server" Text="Button2" OnClick="Button2_Click" />
                       <br />
                       <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                           runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                       </asp:Button>
                       <br />
                       <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                           CommandName="Cancel"></asp:Button>
                   </FormTemplate>
               </EditFormSettings>
           </MasterTableView>
       </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            dynamic data = new[] {
                new { ID1 = 1, ID2 = 2},
                new { ID1 = 4, ID2 = 5}
                
            };
            RadGrid1.DataSource = data;
 
        }
 
        protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
 
        }
 
        protected void Button1_Click(object sender, EventArgs e)
        {
 
        }
 
        protected void Button2_Click(object sender, EventArgs e)
        {
 
        }
.......................................
If you still get the issue then give CommandName other buttons also.
And remove click event from Button.
Do your logic in ItemCommand event of radgrid.

EX :

<asp:Button ID="Button1" runat="server" Text="Button1" OnClick="Button1_Click" CommandName="Mycommmand1" />
....................
  if (e.CommandName == "Mycommmand1")
            {
                // place your button click event here
            }


Let me know if any concern.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Roy Halvorsen
Top achievements
Rank 1
Answers by
Roy Halvorsen
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or