IS Department


Data Controls Tips and Tricks – Session Notes

Posted in Programming by Brian Russell on November 15, 2006

These notes are from the Data Controls Tips and Tricks Session at DevConnections:

To use object binding with more wizard actions in ASP.Net, you need to mark your object supplying the data functionality with attributes.  First, give the class the DataObjectAttribute attribute.  This lets the wizard know what objects are DataObjects.  Next, your individual methods inside these objects need to be marked with the DataObjectMethodAttribute attribute.  This attribute takes arguments.  So, for a select method, you would apply the attribute like so: [DataObjectMethodAttribute(DataObjectMethodType.Select)]

Obviously static and stateless methods work best for object binding in a web world.

The data controls you place on a page (GridView, FormView, DetailsView, etc) offer events to allow you to tap into functionality as things are happening.  Use the DataBound event to hook into items as they are being loaded.  The ItemUpdating, ItemInserting, and ItemDeleting events allow you to tap in before those actions occur (possibly canceling the operation if needed).  The ItemUpdated, ItemInserted, and ItemDeleted allow you to tap into the process after the fact (possibly allow you to adjust the view because of the action).

The DataSource control offers up the Inserted event, which is very useful for grabbing the identity value in order to update the display.  Something like e.Command.Parameters[“@Identity”] works if this is an output parameter.  There are other ways to get the returned value as well.

To confirm a delete with a FormView control, go to the Delete link button and put this in the OnClientClick property:
OnClientClick = “return Confirm(‘Are You Sure’);”

When inserting with the FormView, it needs its InsertVisable property set to false.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: