3

I have this manually update code for my radgrid (RAD13). on upload it works but the thing is that only the first row in the grid saves it's update.

I think that I should passe a value that will autoincrement to passe through rows

protected void UpdateButton_Click(object sender, EventArgs e)
{   
  RadGrid grid = (this.FindControl("RAD13") as RadGrid);               
  (grid.MasterTableView.GetItems(GridItemType.EditItem)[0] as GridEditableItem).FireCommandEvent(RadGrid.UpdateCommandName, string.Empty);           
}  
Jayesh Goyani
  • 11,008
  • 11
  • 30
  • 50

1 Answers1

2

Please try with the below code snippet.

ASPX

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
    OnUpdateCommand="RadGrid1_UpdateCommand" AllowFilteringByColumn="true" AllowPaging="true"
    AllowMultiRowEdit="true">
    <MasterTableView DataKeyNames="ID" EditMode="InPlace">
        <Columns>
            <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
            </telerik:GridBoundColumn>
            <telerik:GridEditCommandColumn>
            </telerik:GridEditCommandColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="update All edit row" />

ASPX.CS

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    dynamic data = new[] {
       new { ID = 1, Name = "Name1"},
       new { ID = 2, Name = "Name2"},
       new { ID = 3, Name = "Name3"},
       new { ID = 4, Name = "Name4"},
       new { ID = 5, Name = "Name5"}
   };

    RadGrid1.DataSource = data;
}



protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
    GridEditableItem item = e.Item as GridEditableItem;
    UpdateLogic(item);
}


protected void Button1_Click(object sender, EventArgs e)
{
    foreach (GridEditableItem item in RadGrid1.EditItems)
    {
        UpdateLogic(item);
        item.Edit = false;
    }

    RadGrid1.Rebind();
}

protected void UpdateLogic(GridEditableItem item)
{
    // perform your update logic here
}

Let me know if any concern.

Jayesh Goyani
  • 11,008
  • 11
  • 30
  • 50