简体   繁体   中英

ASP.NET WinForms C# - How to update Label with value edited in JQGrid

I have a page with JQGrid bound to SqlDataSource1 and Label bound to SqlDataSource2. Both SqlDataSources are selecting from the same table, the first one selects all records and the second one returns only one record which is SelectedRow in JQGrid. Label's Text property is bound to value of one field from that record. All is working fine, but when I click on Edit button in JQGrid and edit selected record in opened dialog, then after dialog is closed, I want to update edited value in my Label too. But JQGrid event RowEdited is not causing postback. Please help me with this.

I don't see the RowEdited event as part of the edit row documentation but there would be other events you could call on to update your label.

What jumped out at me was the aftersavefunction call where you could set the value without having to call the server to update your label.

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#editrow

If you want to use Form Editing then you could tie into the afterComplete function of the call to update your label. This is especially nice as you can get a positive confirmation your edit was saved as part of the afterComplete function before making the change to the label.

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:form_editing

With the help of @Mark I solve this and here is example of javacript (jquery) function I'm using to handle LoadComplete client side event of JQGrid:

<script type="text/javascript">
    function LoadComplete(data) {
        if (data == null) return;
        var selectedRowId = '<%=(Session["SelectedRow"] == null)?string.Empty:Session["SelectedRow"].ToString()%>';
        if (selectedRowId == '') return;
        var rows = $.map(data.rows, function (value) {
            return (value.id == selectedRowId) ? value : null;
        });
        var selectedRow = rows[0];
        var id = selectedRow.cell[0];
        var name = selectedRow.cell[1];
        var surname = selectedRow.cell[2];
        $('#<%= this.lblName.ClientID %>').html(name);
        $('#<%= this.lblSurname.ClientID %>').html(surname);
    }
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM