Sharepoint 2010 - refresh SPGridView
I am working on custom web part. I use SPGridView to display data and dialog window to add new record to SPGridView.

JS for dialog opening & callback:

    //Dialog opening
    function openModal(url) {
        var options = SP.UI.$create_DialogOptions();
        options.url = url;
        options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
        SP.UI.ModalDialog.showModalDialog(options);
    }

    // Dialog callback 
    function CloseCallback(result, target) {
        if (result === SP.UI.DialogResult.OK) {          
            //setTimeout("location.reload(true)", 1200); - I also tried this for page refresh, it's not good for my solution
            SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
        }
    }

After page refresh, new record is added to SPGridVIew. I have problem with binding records ID to hidden field. After page refresh is in this hidden field stored ID of previous record.

SPGridView:

    <SharePoint:SPGridView ID="SPGridVIew1" runat="server" EnableModelValidation="True" AutoGenerateColumns="False" EnableViewState="False">
       <Columns>
          <asp:TemplateField HeaderText="Hidden field ID">
             <ItemTemplate>
                <asp:CheckBox ID="RowSelector" runat="server" CssClass="RowCheckbox" />
                <asp:HiddenField ID="RowId" runat="server" Value='<%# Bind("ID") %>' />
             </ItemTemplate>
          </asp:TemplateField>
          <SharePoint:SPBoundField DataField="ID" HeaderText="ID" />
       </Columns>
    </SPGridView>

Example output before adding new record:      

    Hidden Filed ID  |  ID
    -----------------------
    1                |  1

Example output after adding new recor:

    Hidden Filed ID  |  ID
    -----------------------
    1                |  2
    1                |  1

So, how to put newly added record ID to hidden field? Thanks for help!


Sharepoint 2010 - refresh SPGridView
===

I am working on custom web part. I use SPGridView to display data and dialog window to add new record to SPGridView.

JS for dialog opening & callback:

    //Dialog opening
    function openModal(url) {
        var options = SP.UI.$create_DialogOptions();
        options.url = url;
        options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
        SP.UI.ModalDialog.showModalDialog(options);
    }

    // Dialog callback 
    function CloseCallback(result, target) {
        if (result === SP.UI.DialogResult.OK) {          
            //setTimeout("location.reload(true)", 1200); - I also tried this for page refresh, it's not good for my solution
            SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
        }
    }

After page refresh, new record is added to SPGridVIew. I have problem with binding records ID to hidden field. After page refresh is in this hidden field stored ID of previous record.

SPGridView:

    <SharePoint:SPGridView ID="SPGridVIew1" runat="server" EnableModelValidation="True" AutoGenerateColumns="False" EnableViewState="False">
       <Columns>
          <asp:TemplateField HeaderText="Hidden field ID">
             <ItemTemplate>
                <asp:CheckBox ID="RowSelector" runat="server" CssClass="RowCheckbox" />
                <asp:HiddenField ID="RowId" runat="server" Value='<%# Bind("ID") %>' />
             </ItemTemplate>
          </asp:TemplateField>
          <SharePoint:SPBoundField DataField="ID" HeaderText="ID" />
       </Columns>
    </SPGridView>

Example output before adding new record:      

    Hidden Filed ID  |  ID
    -----------------------
    1                |  1

Example output after adding new recor:

    Hidden Filed ID  |  ID
    -----------------------
    1                |  2
    1                |  1

So, how to put newly added record ID to hidden field? Thanks for help!

