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

[Solved] Gird Add new record

3 Answers 219 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prakash
Top achievements
Rank 1
Prakash asked on 26 Aug 2013, 04:21 AM

Hi,

  Please let me know how to open insert item template when grid is in batch edit mode from code behind.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Aug 2013, 11:42 AM
Hi,

With reference to this post When EditMode is set to Batch,an editor is created for each column and is only shown when a user clicks on a certain cell to edit it's content. Later when the cell value is changed a client side object is created which reflect the changes. If another cell from the same column is opened for editing the editor is being repopulated in order to expose the value from that cell. This logic is being executed on the client using JavaScript. The values are passed to the server once the Save Changes button is pressed.

Also note that if the edit mode is set to Batch and a control on the page postback the changes made by the user will be lost as RadGrid will retrieve it's initial state. One suggestion is to open insert form from client side.

Please check the following code snippet to open Insert mode on a an external button click.

ASPX:
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="OnClientClick();return false" />

Javascript:
<script type="text/javascript">
    function OnClientClick() {       
     var grid = $find("<%= RadGrid1.ClientID %>");
     var mastertableview = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
     grid.get_batchEditingManager().addNewRecord(mastertableview);      
   
</script>

Thanks,
Princy.
0
Prakash
Top achievements
Rank 1
answered on 26 Aug 2013, 12:16 PM
Thanks,

That works great.

For server side how to do the same.

Radgrid.MasterTableView.IsItemInserted = true;

This opens insert item template like editinform editmode.
0
Princy
Top achievements
Rank 2
answered on 27 Aug 2013, 05:42 AM
Hi,

I dont think its possible to use 'Radgrid.MasterTableView.IsItemInserted = true;' in server side to open a batch insert form from server side. You can call the client side function from server side as follows.

ASPX:
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

C#:
protected void Button1_Click(object sender, EventArgs e)
{
      string script = "function f(){showInsertForm(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
      ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
}

Javascript:
<script type="text/javascript">
    function showInsertForm() {      
     var grid = $find("<%= Radgrid.ClientID %>");
     var mastertableview = grid.get_masterTableView();
     grid.get_batchEditingManager().addNewRecord(mastertableview);     
   }
</script>

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