An Overview of Editing Functions

only for RuBoard

The way you enable editing for the DataGrid is similar to the method for the DataList , which is why we are combining them in this chapter. In this section, I want to give you a high-level picture of how editing works. I'll be mentioning certain attributes and events that might not make sense to you right now, but they'll become clear to you later in the chapter when we start building and dissecting the example code.

When editing is enabled for a DataGrid , you must have an EditCommandColumn . This is nothing more than a container column for an object that the users click to go into edit mode. The DataList also has a way for users to put it into edit mode, but you have to create the buttons manually using either a Button or LinkButton control because the DataList is built entirely from templates. Once the page is rendered and a user clicks the Edit button, then the form is posted back to the server and the EditCommand event is raised. This is where you'll code to put the DataGrid or DataList into edit mode.

After it's in edit mode, the row selected by the user to be edited will contain editable controls such as a text box. Two new buttons can be used while in edit mode: Update and Cancel button. Update is used to raise the UpdateCommmand event, which is where you save any changes back to your data source. Cancel is used to raise the CancelCommand event, which switches the DataGrid or DataList out of edit mode without making changes to the underlying data source.

There are four different events used for enabling editing data using the DataGrid and DataList . You must handle these events appropriately to make editing work:

  • EditCommand ” Raised by the OnEditCommand method when the Edit button is clicked.

  • UpdateCommand ” Raised by the OnUpdateComman d method when the Update button is clicked.

  • DeleteCommand ” Raised by the OnDeleteCommand method when the Delete button is clicked

  • CancelCommand ” Raised by the OnCancelCommand method when the Cancel button is clicked.

In order for these events to be fired , you must tell the DataGrid or DataList by setting the following attributes:

  • OnEditCommand ” The value is the method name you're using to handle the EditCommand event.

  • OnUpdateCommand ” The value is the method name you're using to handle the UpdateCommand event.

  • OnDeleteCommand ” The value is the method name you're using to handle the DeleteCommand event.

  • OnCancelCommand ” The value is the method name you're using to handle the CancelCommand event.

only for RuBoard


Programming Data-Driven Web Applications with ASP. NET
Programming Data-Driven Web Applications with ASP.NET
ISBN: 0672321068
EAN: 2147483647
Year: 2000
Pages: 170

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net