Terry

Terry

  • NA
  • 148
  • 0

What can be the best way to manage GridView <-> FormView <->

May 31 2015 3:00 PM
Hello,
 
    In ASP.NET 4.5 using Entity Framework under WebForms app -
Show Data of selected row of GridView in FromView.
Change the Mode of FormView
Edit/Insert Data in Form View 
 
Have Save button outside of Grid & Form views'. On click of Save button, want to call UpdateMethod of FormView that will validate, show errors in validation summary (if any) & finally save the data to db.
 
Using DataSource & Databind for FormView, my Item, Edit & Insert  templates are working as expected. But with Save button, I am not able to call UpdateMethod - as for that I need to have SelectMethod in FormView.
If SelectMethod is set (removing Datasource & Databind part), the data is always blank. 
 
 I don't wish to write the validation part again & go this way :
public void inqFormView_UpdateItem(int id)
{
 Inquiry item = null;
// Load the item here, e.g. item = MyDataLayer.Find(id);
if (item == null)
{
// The item wasn't found
ModelState.AddModelError("", String.Format("Item with id {0} was not found", id));
return;
}
TryUpdateModel(item);
if (ModelState.IsValid)
{
// Save changes here, e.g. MyDataLayer.SaveChanges();
}
}
 
 Can you please suggest the best and suitable methodology for this situation ?? 
 Any help is highly apprecited. Am stuck on this since last 3-4 days, and can't get a way for it. So please help me.
 
Thanks
 
 
 

Answers (8)