Jump to content
Software FX Community

GridFX Updating an item in place


mgamage

Recommended Posts

Hello,

My company has purchased GridFX and is using it in several locations in our web application. I'm currently developing a new module that requires in place editing of rows in the grid. I have followed the instructions in the Programmers Guide and implemented the 'onitemupdating' event as follows :

  protected void GridNotesAttachments_ItemUpdating(object sender, GridItemUpdatedEventArgs e)   {   if (GridNotesAttachments.Items.Count > 0)   {   if (!e.OldValues["attachment_desc"].ToString().Equals(e.NewValues["attachment_desc"].ToString()))   {   EntNoteAttachment attachment = new EntNoteAttachment();   attachment.NoteId = (int)e.OldValues["note_id"];     attachment.AttachmentId = (int?)e.Keys["attachment_id"];   attachment.Description = e.NewValues["attachment_desc"].ToString();   attachment.FileName = e.OldValues["attachment_name"].ToString();   attachment.FilePath = e.OldValues["attachment_loc"].ToString();   DataView dvAttachments = new DataView();   dvAttachments = (DataView)Session["attachments_collection"];   dvAttachments.Sort = "attachment_id";     int rowIndex = 0;   rowIndex = dvAttachments.Find(attachment.AttachmentId);   dvAttachments.Delete(rowIndex);   DataRowView newRow = dvAttachments.AddNew();     newRow["note_id"] = NoteId;   newRow["attachment_id"] = attachment.AttachmentId;   newRow["attachment_desc"] = attachment.Description;   newRow["attachment_name"] = attachment.FileName;   newRow["attachment_loc"] = attachment.FilePath;   newRow.EndEdit();     GridNotesAttachments.DataSource = dvAttachments;   Session["attachments_collection"] = GridNotesAttachments.DataSource;   e.KeepInEditMode = false;   }   else   {   e.ErrorMessage = "No changes made.";   }   }   }

 

When I try to edit a row in place, and click on the ok symbol on the edit widget , I get the following error message :

" There was a problem while processing your request. The specific error message was: There was an error in the callback."

 

Can you please provide some guidance as to why its doing this and what I might be doing wrong.

 

ThanksMadusha 

 

Link to comment
Share on other sites

Thanks for using Grid FX.

I was checking your code and I found a few things that you should adjust. First, Items count validation is not necessary. Second, you have to set e.Handled property = True and third, you don't have to re-bind the grid in the updating event; this should be coded in the Grid.Databind event or similar.

I would like to check your data binding event and also it would be nice to know why you are saving a DataView in the Session object. It would help me understand your application needs and give you an accustomed advice.

Following is you original code with those changes I previously mentioned you.

 

protected void GridNotesAttachments_ItemUpdating(object sender, GridItemUpdatingEventArgs e)

  {

  //Grid FX validates Items count > 0. This explicit validation is not required.

  //if (GridNotesAttachments.Items.Count > 0)

  //{

  if (!e.OldValues["attachment_desc"].ToString().Equals(e.NewValues["attachment_desc"].ToString()))

  {

  EntNoteAttachment attachment = new EntNoteAttachment();

 

  attachment.NoteId = (int)e.OldValues["note_id"];

  attachment.AttachmentId = (int?)e.Keys["attachment_id"];

  attachment.Description = e.NewValues["attachment_desc"].ToString();

  attachment.FileName = e.OldValues["attachment_name"].ToString();

  attachment.FilePath = e.OldValues["attachment_loc"].ToString();

 

  DataView dvAttachments = new DataView();

 

  dvAttachments = (DataView)Session["attachments_collection"];

  dvAttachments.Sort = "attachment_id";

 

  int rowIndex = 0;

  rowIndex = dvAttachments.Find(attachment.AttachmentId);

 

  try

  {

  dvAttachments.Delete(rowIndex);

 

  DataRowView newRow = dvAttachments.AddNew();

 

  newRow["note_id"] = NoteId;

  newRow["attachment_id"] = attachment.AttachmentId;

  newRow["attachment_desc"] = attachment.Description;

  newRow["attachment_name"] = attachment.FileName;

  newRow["attachment_loc"] = attachment.FilePath;

 

  newRow.EndEdit();

 

//It's not necessary to bind the grid here, you could use Data binding event

  //GridNotesAttachments.DataSource = dvAttachments;

 

  //Session["attachments_collection"] = GridNotesAttachments.DataSource;

 

  e.KeepInEditMode = false;

 

  }

  finally

  {

  // Set Handled property to true

  e.Handled = true;

  }

  }

  else

  {

  e.ErrorMessage = "No changes made.";

  }

 

  //}

 

  }

Let me know if this helps. I'll look forward for your answer.

 

Link to comment
Share on other sites

 Thank you for the quick response!

 I'm still having the same issue after making the suggested changes. Any suggestions? 

The code for the grid's DataBinding event is as follows:

protected void GridNotesAttachments_DataBinding(object sender, EventArgs e)   {   if (!IsPostBack)   {   try   {   EntNote note = (EntNote)Session["note"];   DataSet dsAttachments = new DataSet();   NotesBC bcNotes = new NotesBC();   dsAttachments = bcNotes.GetAttachmentsByNote(UserIdentity, (int)note.NoteId);   DataView dvAttachments = dsAttachments.Tables[0].DefaultView;   GridNotesAttachments.DataSource = dvAttachments;   Session["attachments_collection"] = GridNotesAttachments.DataSource;   }   catch (Exception ex)   {   _vldSummary.AddException(ex);   }   }   }

 

To briefly fill you in on why I'm doing things the way I am:

I'm using an unbound grid and is populating the grid using business object methods. In this part of the application when a user adds a row to the grid I do not wish to write that change immediately to the database, but want to save it in some temporary location (in this case I thought I would use the underlying grids dataview) and reflect the change visually on the grid. Only when the user explicitly clicks on a 'Save' button should the data changes be made to the database. I guess I'm doing this as I was unable to do any client side scripting on the grid, otherwise I could have just added the new row to the grid using JS (which leads me to another question, Is there going to be any client side API documentation for this grid?) 

Also, the reason why I'm saving a copy of the grid's datasource DataView in Session is because I found that the grid doesnt retain its DataSource property on postbacks (is it supposed to?)

 Thanks for your assistance.

Madusha 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...