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

Raise Master Table View Add New Record Button in code behind

1 Answer 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cindy
Top achievements
Rank 1
Cindy asked on 02 Dec 2016, 04:48 PM

I'm hoping that someone can help me. I have a radgrid with a Add New Sales Opportunity button on the command bar at the top of the MasterTableView. When clicked the ItemCreated event is fired. I have a JavaScript alert that asks if the user wants to create another record after they have saved their first. I am using a HiddenField on the user control to send the response back to the server side. What I need to do is raise the ItemCreated event in the code behind to open a new add form if the user options to create a new record. 

Here's a snippet of how my grid is created in the user control:

<telerik:RadGrid  runat="server" ID="grdSalesOpportunity" CssClass="grdSalesOpportunityClass" AllowPaging="True" AllowCustomPaging="true" 
                AutoGenerateColumns="false" EnableLinqExpressions="false"
                AllowSorting="true" GridLines="Both" OnNeedDataSource="grdSalesOpportunity_NeedDataSource" CommandItemStyle-CssClass="swrap"
                OnItemDataBound="grdSalesOpportunity_ItemDataBound"
                NonExportingColumns="EditCommandColumn,DeleteColumn,AddNotes" ShowAllExportButtons="false"
                OnSortCommand="grdSalesOpportunity_SortCommand" OnPageSizeChanged="grdSalesOpportunity_PageSizeChanged"
                OnUpdateCommand="grdSalesOpportunity_UpdateCommand" OnInsertCommand="grdSalesOpportunity_InsertCommand"
                OnItemCommand="grdSalesOpportunity_ItemCommand" OnItemCreated="grdSalesOpportunity_ItemCreated" ShowExtraButtons="true">
                <ClientSettings Scrolling-AllowScroll="true" Scrolling-UseStaticHeaders="true"></ClientSettings>
                <GroupingSettings CaseSensitive="false" />
                <ExportSettings ExportOnlyData="True" IgnorePaging="True" OpenInNewWindow="True"
                    Pdf-PageWidth="350mm" Pdf-PageHeight="210mm" Pdf-PageLeftMargin="20mm" Pdf-PageRightMargin="20mm">
                </ExportSettings>

                <MasterTableView CommandItemDisplay="Top" DataKeyNames="SOID" AllowFilteringByColumn="true"
                    ClientDataKeyNames="SOID">
                    <CommandItemSettings ShowAddNewRecordButton="true" AddNewRecordText="Add New Sales Opportunity"
                        ShowExportToCsvButton="true" ShowExportToExcelButton="true" ShowExportToPdfButton="true"
                        ShowExportToWordButton="false" />

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 07 Dec 2016, 11:17 AM
Hello Cindy,

You can fire grid commands using fireCommand method on client-side:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/client-side-programming/gridtableview-object/methods/firecommand

Or using FireCommandEvent method on server-side:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/control-lifecycle/how-to-fire-command-events

The built-in command for Add New Record is called InitInsert.

I hope this will prove helpful.

Regards,
Eyup
Telerik by Progress
Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
Tags
Grid
Asked by
Cindy
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or