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

5 posts, 0 answers
  1. aykut
    aykut avatar
    67 posts
    Member since:
    Oct 2007

    Posted 19 Aug 2014 Link to this post

    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 ?

        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
            End If
        End Sub
        Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            If IsPostBack = False Then
       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
            ' here I add some more rows.....
            Session("RequestMonetDataTable") = dt
        End Sub
  2. aykut
    aykut avatar
    67 posts
    Member since:
    Oct 2007

    Posted 19 Aug 2014 Link to this post

    in other words how can I call BatchEditCommand from server side ?
  3. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 Aug 2014 in reply to aykut Link to this post

    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.

    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);
            string query = "UPDATE Products SET product='" + newValues["product"] + "' WHERE ID= '" + editedItem.GetDataKeyValue("ID").ToString() + "'";
            SqlCommand cmd = new SqlCommand(query, conn);
            editedItem.Edit = false;

  4. Puja
    Puja avatar
    5 posts
    Member since:
    Jan 2018

    Posted 30 Aug 2018 Link to this post

    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

  5. Marin Bratanov
    Marin Bratanov avatar
    5915 posts

    Posted 03 Sep 2018 Link to this post

    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.

    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.
Back to Top