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.