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

RadGrid Editing,Deleting,Inserting

2 Answers 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amit
Top achievements
Rank 1
Amit asked on 04 Oct 2010, 08:10 AM
Hey there,

I am using a RadGrid in which i am using a dataset as datasource and bringing complete database table on the grid.I am using Buttond for Edit,Delete and Save outside the grid on Row Select.I have made an asp:Panel under the grid to show the textBoxes for editing values for the selected row.Now my asp:panel contains 2 buttons save and cancel.

My problem is:--
   The values of the selected rows are shown in the textBoxes on panel for editing,And after editing when i click save I've hided the panel but values are not saved in the row.Unless postback takes place,like if i select another row and click edit then page postbacks and the row edited previously now shows the edited values in the gridRow.
 
  I am not using Need Data Suorces event of Grid.Is it mandatory to use?
  If so whats the proper method of implementing it in my case?


Thanks
Amit.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Oct 2010, 08:28 AM
Hello Amit,


Have you rebind the grid after updating the values?

You can find the demo of using external edit form for radgrid here:
http://demos.telerik.com/aspnet-ajax/ajax/examples/manager/dynamicajaxsettings/defaultcs.aspx?product=grid

A better option to populate the grid is by using NeedDataSource event (AdvancedDataBinding) if you are using any complex operations in on grid. For advanced features like grouping, hierarchy presentation, filtering. etc. Telerik RadGrid requires advanced data-binding through its NeedDataSource event or a data source control.


Thanks,
Princy.
0
Amit
Top achievements
Rank 1
answered on 04 Oct 2010, 09:12 AM
I am doing this

protected void SaveChanges_Click(object sender, EventArgs e)  //On edit click after selecting a row
        {
            pnlExternalForm.Visible = true;
            RadGrid Grid = (this.FindControl("RadGrid1") as RadGrid);
            string Pid = Convert.ToString(Grid.SelectedValues["Pid"]);
            string query = "SELECT * FROM tblProducts where Pid='" + Pid + "'";
            GetProductInfoForEdit(query, Pid);
        }

        private void GetProductInfoForEdit(string query, string ProductId)
        {
            DataSet ds = objSQLHelper.GetInventoryForm(query);
            txtItemNamePanel.Text = Convert.ToString(ds.Tables[0].Rows[0]["ProductName"]);
            txtQtyAvailablePanel.Text = Convert.ToString(ds.Tables[0].Rows[0]["QtyAvailable"]);
            txtRatePanel.Text = Convert.ToString(ds.Tables[0].Rows[0]["Rate"]);
            lblIdPanel.Text = ProductId;
        }
        protected void btnSaveChanges_Click(object sender, EventArgs e)//Save button on panel after editing values in the text boxes
        {
            if (!string.IsNullOrEmpty(lblIdPanel.Text))
            {
                UpdateProductInfo();
                BindGrid();
            }
        }

        private void UpdateProductInfo()
        {
            try
            {
                int result = objSQLHelper.UpdateRowsInDb(Convert.ToInt32(lblIdPanel.Text), Convert.ToString(txtItemNamePanel.Text), Convert.ToInt32(txtQtyAvailablePanel.Text), Convert.ToInt32(txtRatePanel.Text));
                RadGrid1.Rebind();  //Here i have rebinded after Update
                HidePanel();
            }
            catch (Exception ex)
            {

            }
        }
Tags
Grid
Asked by
Amit
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Amit
Top achievements
Rank 1
Share this question
or