Click here to Skip to main content
16,021,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

This is my code--

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);
BindGrid();
}

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;
BindGrid();
}
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));
BindGrid();//Here i have rebinded after Update
HidePanel();
}
catch (Exception ex)
{

}
}

private void HidePanel()
{
txtItemNamePanel.Text = "";
txtQtyAvailablePanel.Text = "";
txtRatePanel.Text = "";
lblIdPanel.Text = "";
pnlExternalForm.Visible = false;
}

Thanks
Amit.
Posted

1 solution

Well, either using XMLHttpRequest maintain the changes on server side OR commit the changes once panel is closed.

I am not sure, but if your Radgrid supports editing number of rows at once and commit later than you can try that too.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900