invoke method batcheditcommand from C#.net [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 08:17:53

问题


I used telerik:RadGrid batch editing; to fill this grid I used below syntax:

function GridBind(GridID, GridData) {
    var TableView = GridID.get_masterTableView();
    TableView.set_dataSource(GridData); TableView.dataBind();
}

To Invoke batcheditcommand I used below syntax. It’s written under non-postback button Javascript event:

function SaveAllChanges(sender,args) {
    var batchManager = $find('<%=RadGrid1.ClientID%>').get_batchEditingManager();
    var tableViews = [];
    tableViews.push($find('<%=RadGrid1.ClientID%>').get_masterTableView());
    batchManager.saveTableChanges(tableViews);
}

But unfortunately it did not fire server event RadGrid1_BatchEditCommand, so I want to invoke Radgrid batcheditcommand from code behind in C#.net.


回答1:


A quick POC that worked for me:

markup:

    <telerik:RadGrid ID="RadGrid1" runat="server" OnBatchEditCommand="RadGrid1_BatchEditCommand">
        <MasterTableView EditMode="Batch">
            <Columns>
                <telerik:GridBoundColumn DataField="first"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="second"></telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
    <asp:Button ID="Button1" Text="bind grid" OnClientClick="bindTheGrid(); return false;" runat="server" />
    <asp:Button ID="Button2" Text="save grid" OnClientClick="SaveAllChanges(); return false;" runat="server" />
    <script>
        function bindTheGrid() {
            var grid = $find("<%=RadGrid1.ClientID%>");
            var data = [{ first: 1, second: 1 }, { first: 2, second: 2 }];
            GridBind(grid, data);
        }
        function GridBind(GridID, GridData) {
            var TableView = GridID.get_masterTableView();
            TableView.set_dataSource(GridData);
            TableView.dataBind();
        }

        function SaveAllChanges(sender, args) {
            var batchManager = $find('<%=RadGrid1.ClientID%>').get_batchEditingManager();
            var tableViews = [];
            tableViews.push($find('<%=RadGrid1.ClientID%>').get_masterTableView());
            batchManager.saveTableChanges(tableViews);
        }
    </script>

and server code

protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            RadGrid1.DataSource="";
            RadGrid1.DataBind();
        }
    }
    protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
    {
        Response.Write(DateTime.Now.ToString());
    }

where you would need to work a bit on the client-side binding.

Make sure you have no script errors.

In the first function, do you pass a grid object or an ID in the GridID object? If only and ID, use $find() first to get a reference.



来源:https://stackoverflow.com/questions/28815837/invoke-method-batcheditcommand-from-c-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!