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

Insert/update grid items in button outside grid

3 Answers 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Venkatesh
Top achievements
Rank 1
Venkatesh asked on 04 Dec 2012, 06:07 AM
Hi,
I am using the Rad Grid available in "RadControls for ASP.NET AJAX Q3 2012" in Sharepoint 2010(vs2010/c# 3.5).
I have a visual webpart, which has 5 textbox, radgrid and a submit button.

Currently i have the items in the grid getting inserted/deleted/updated in the "oninsertcommand/ondeletecommand/onupdatecommand" events.

However, I want to do these grid changes only when the submit button is clicked. How to achieve this?
Thanks

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Dec 2012, 06:29 AM
Hi,

One suggestion is that you can use FireCommand as shown below.
C#:
protected void submit_Click(object sender, EventArgs e)
{
  GridCommandItem commandItem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
  commandItem.FireCommandEvent("InitInsert", null);
}

Thanks,
Shinu.
0
Venkatesh
Top achievements
Rank 1
answered on 04 Dec 2012, 07:02 AM

Hi,
Thanks for the reply.
Currently i have the code as below:

<telerik:RadGrid ID="RadGrid1" runat="server" EnableViewState="true" ShowStatusBar="true"
        ShowFooter="True" onitemcommand="RadGrid1_ItemCommand" 
        ondeletecommand="RadGrid1_DeleteCommand" 
        oninsertcommand="RadGrid1_InsertCommand" 
        onupdatecommand="RadGrid1_UpdateCommand" 
        onneeddatasource="RadGrid1_NeedDataSource" >
    <MasterTableView DataKeyNames="Title" AutoGenerateColumns="false" EditMode="InPlace" CommandItemDisplay="TopAndBottom" CommandItemSettings-AddNewRecordText="Add New Item" >
                    <Columns>
                     <telerik:GridEditCommandColumn ButtonType="ImageButton">
                        </telerik:GridEditCommandColumn>
                        <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                            ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" ConfirmDialogHeight="100px"
                            ConfirmDialogWidth="220px">
                        </telerik:GridButtonColumn>
  
                     <telerik:GridTemplateColumn DataField="Title" HeaderText="Product Number" UniqueName="ProductNumber"
                            Visible="true">
                            <InsertItemTemplate>
                                <telerik:RadTextBox ID="RadtxtPrdNumber" runat="server" Text='<%# Bind("Title") %>' >
                                </telerik:RadTextBox>
                            </InsertItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadTextBox ID="RadtxtPrdNumber" runat="server" Text='<%# Eval("Title") %>' >
                                </telerik:RadTextBox>
                            </EditItemTemplate>    
                            <ItemTemplate>
                            <telerik:RadTextBox ID="RadtxtPrdNumber" ReadOnly="true" runat="server" Text='<%# Eval("Title") %>' />
                            </ItemTemplate>                       
                        </telerik:GridTemplateColumn>
  
 </Columns>
      
    </MasterTableView>
     <ClientSettings EnableRowHoverStyle="true">
        </ClientSettings>
  
    </telerik:RadGrid>
  
  
<asp:Button ID="btnSubmit" runat="server" Text="Submit" 
        onclick="btnSubmit_Click" />
So, in the above code i can remove the Insercommand,editcommand,deletecommand and use the code as you provided for submit. Is this rite.

Thanks
0
Shinu
Top achievements
Rank 2
answered on 05 Dec 2012, 08:01 AM
Hi,

FireCommand is used to raise command events like Edit/Update/Delete i.e InitInsert command name will fire the RadGrid1_InsertCommand event. Also check the following help documentation which explains more about this.
How to fire command events from code

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