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

Update radgrid with external button (all rows in edit mode)

4 Answers 736 Views
Grid
This is a migrated thread and some comments may be shown as answers.
aykut
Top achievements
Rank 1
aykut asked on 19 Aug 2014, 01:18 PM
hi there,
I have some textboxes (for name, surname etc) and and a radgrid on my web page.(for products for example). all radgrid's rows are in "inplace" edit mode.. When I press to external button, form postbacks. meanwhile All information user entered in ragrid get lost. I think I have to update radgrid first but I don't know how ? because there's no update command column in grid. all rows in edit mode and while postingback I need to update all of them at once. How can achieve this ?
best



    Protected Sub radGridProducts_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles radGridProducts.NeedDataSource
        Dim dt As New DataTable
        dt = DirectCast(Session("RequestMonetDataTable"), DataTable)
        radGridProducts.DataSource = dt
    End Sub
 
    Protected Sub radGridProducts_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles radGridProducts.PreRender
        If Not IsPostBack Then
            For Each item As GridItem In radGridProducts.MasterTableView.Items
                If TypeOf item Is GridEditableItem Then
                    Dim editableItem As GridEditableItem = CType(item, GridDataItem)
                    editableItem.Edit = True
                End If
            Next
            radGridProducts.Rebind()
        End If
    End Sub
 
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If IsPostBack = False Then
            CreateDataSource()
   end If
 
    Protected Sub CreateDataSource()
        Dim dt As New DataTable
        Dim dr As DataRow
 
        dt.Columns.Add(New Data.DataColumn("ID", GetType(String)))
        dt.Columns.Add(New Data.DataColumn("product", GetType(String)))
        dt.Columns.Add(New Data.DataColumn("quantity", GetType(Integer)))
        dt.Columns.Add(New Data.DataColumn("price", GetType(Decimal)))
 
 
        dr = dt.NewRow
        dr("ID") = 1
        dr("product") = "aaa"
        dr("quantity") = 0
        dr("price") = 0
        dt.Rows.Add(dr)
       
        ' here I add some more rows.....
 
        Session("RequestMonetDataTable") = dt
  
    End Sub

4 Answers, 1 is accepted

Sort by
0
aykut
Top achievements
Rank 1
answered on 19 Aug 2014, 01:27 PM
in other words how can I call BatchEditCommand from server side ?
0
Princy
Top achievements
Rank 2
answered on 20 Aug 2014, 06:30 AM
Hi aykut,

I guess you want to update all rows from server side. On the button's OnClick event you can try the following code snippet to save all values at once.

C#:
protected void btnUpdate_Click(object sender, EventArgs e)
{
    foreach (GridEditableItem editedItem in RadGrid1.EditItems)
    {
        Hashtable newValues = new Hashtable();
        //The GridTableView will fill the values from all editable columns in the hash
        editedItem.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
        conn.Open();
        string query = "UPDATE Products SET product='" + newValues["product"] + "' WHERE ID= '" + editedItem.GetDataKeyValue("ID").ToString() + "'";
        SqlCommand cmd = new SqlCommand(query, conn);
        cmd.ExecuteNonQuery();
        conn.Close();
 
        editedItem.Edit = false;
    }
    RadGrid1.Rebind();
}

Thanks,
Princy
0
Puja
Top achievements
Rank 1
answered on 30 Aug 2018, 11:04 AM

How can I achieve Insertion radgrid with external button (all rows in edit mode).

I am using the same code to achieve the editable rows and updation

0
Marin Bratanov
Telerik team
answered on 03 Sep 2018, 04:15 PM
Hi Puja,

If you want to have all rows editable at the same time, perhaps the batch editing mode will be more suitable for your needs: https://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/batch-editing/defaultcs.aspx.

If the built-in Add New Record button does not suffice for your needs, you can use the batch editing client-side api to create a new row (see the addNewRecord method): https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/edit-mode/batch-editing/client-side-api. Note that such an external button must not invoke postbacks as this will wipe the data in the grid. You can read more about such a scenario in the following article: https://www.telerik.com/support/kb/aspnet-ajax/grid/details/how-to-update-batch-edit-grids-from-outside-button-and-also-save-external-user-input.


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
aykut
Top achievements
Rank 1
Answers by
aykut
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Puja
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or