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

call RadGrid_ItemCommand from a different method

3 Answers 157 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 09 Nov 2010, 05:40 PM
Hi,

I have an issue where I need to RadGrid_ItemCommand from a seperate public method which in turn will be called by a different control.
Does anyone have any example of how this can be done?

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Nov 2010, 04:53 AM
Hello John,

In order to achieve this, you can use FireCommandEvent method as described in the following documentation.
How to fire command events from code

Thanks,
Princy.
0
John
Top achievements
Rank 1
answered on 10 Nov 2010, 10:04 AM
Hi,

thanks but I still cannot get this to work, let me try and explain what I'm trying to do in some more detail.

My RadGrid has a modal popup used to add new records, this is shown below. What I want to do is get this modal popup to be triggered by a new Method, in this case called AddNew in the code behind.

EditForm markup
<EditFormSettings InsertCaption="Add Note" CaptionFormatString="View Note" EditFormType="Template">
            <PopUpSettings Modal="true" />
            <FormTemplate>
                <table id="tblAddNote" cellspacing="1" cellpadding="1" width="250px" border="0">
                    <tr>
                        <td>
                            <asp:TextBox ReadOnly='<%# !(Container is GridEditFormInsertItem) %>' Width="400px" Height="150px" TextMode="MultiLine" ID="txtNote" Text='<%# Bind( "Content") %>' runat="server">
                            </asp:TextBox>
                        </td>
                    </tr>
                </table>
                <table style="width: 100%">
                    <tr>
                        <td align="right" colspan="2">
                            <asp:Button ID="btnUpdate"  Text='<%# (Container is GridEditFormInsertItem) ? "Add" : "Close" %>'
                                runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Cancel" %>'>
                            </asp:Button
                            <asp:Button ID="btnCancel" Visible="<%# (Container is GridEditFormInsertItem) %>" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
                            </asp:Button>
                        </td>
                    </tr>
                </table>
            </FormTemplate>
        </EditFormSettings>


Code behind calling mathod
protected void RadGrid_ItemCommand(object sender, GridCommandEventArgs e)
       {
           if (e.Item is GridCommandItem && e.CommandName == "InitInsert")
           {
               RadGrid.MasterTableView.NoMasterRecordsText = string.Empty;
           }
       }
 
       public void AddNew()
       {
           GridCommandItem GCI = new GridCommandItem(RadGrid.MasterTableView);
           RadGrid.MasterTableView.NoMasterRecordsText = string.Empty;
           //RadGrid.RaisePostBackEvent(string.Empty);
           GCI.FireCommandEvent("InitInsert", String.Empty);
            
            
       }
0
Princy
Top achievements
Rank 2
answered on 11 Nov 2010, 11:41 AM
Hello John,

Try the following approach to access GridCommandItem and check whether it works now.

C#:
public void AddNew()
  {
      GridCommandItem GCI = (GridCommandItem)RadGrid.MasterTableView.GetItems(GridItemType.CommandItem)[0];
      GCI.FireCommandEvent("InitInsert", String.Empty);
  }

Thanks,
Princy.
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
John
Top achievements
Rank 1
Share this question
or