Web Venture 101


Keys, Values, and NewValues when Inserting, Updating, Deleting with GridView, DetailsView, FormView and ObjectDataSource

, posted: 9-May-2006 15:06

It takes a bit of getting used to when and how to insert values on inserting, updating, and deleting when using ObjectDataSources with the DetailsView, FormView, and GridView. 

You need to figure out which part of the EventArgs to modify to get your action to have all the correct data... sometimes its the Values collection, sometimes the NewValues, and sometimes the Keys.

For example:

Details/FormView Inserting...

BlahDetailsView_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
  ...
  e.Values.Add("blahId", object);
  ...
}

and

BlahFormView_ItemInserting(object sender, FormViewInsertEventArgs e)
{
  ...
  e.Values.Add("blahId", object);
  ...
}


FormView Updating

BlahFormView_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
  ...
  ListBox listBox1 = (ListBox)LoginView1.Controls[0].Controls[1].FindControl("ListBox1");
  e.NewValues.Add("BlahId", listBox1.SelectedValue);
  ...
}


GridView Row Deleting

GridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
  ...
  e.Keys.Add("blahId", object);
  ...
}


I'm sure there's a logic to it, but I'm just getting used to it.


Other related posts:
Creating Typed Datasets - member names cannot be the same as their enclosing type
Finding controls inside ItemTemplates inside a FormView inside a LoginView
Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query






Comment by Kim Meyer, on 19-Jun-2006 21:13

There appears to be so little info on the net regarding real world nuts@bolts examples inserting child records in a DetailsView. Especially when its connected to a GridView and you wish to pass some values to a DetailsView on a separate page. Have you come across any good books on database asp.net 2.0 front ends.


Add a comment

Please note: comments that are inappropriate or promotional in nature will be deleted. E-mail addresses are not displayed, but you must enter a valid e-mail address to confirm your comments.

Are you a registered Geekzone user? Login to have the fields below automatically filled in for you and to enable links in comments. If you have (or qualify to have) a Geekzone Blog then your comment will be automatically confirmed and shown in this blog post.

Your name:

Your e-mail:

Your webpage:

ptorrsmith's profile

Peter Torr Smith
Wellington
New Zealand


I've been working on a web venture idea for the last year or so, so have now resigned from my job to go at it full-time.

Here's how I go, with business and technology challenges!!