ASP.NET DataList control events - How to Handle the DataList control events?

          

ASP.NET Handling the DataList control events


<<Previous

Book Excerpt: Working with the DataList Control

In this chapter, we will cover the ASP.NET DataList control. We will learn about the following:

>Using the DataList control
>Binding images to a DataList control dynamically
>Displaying data using the DataList control
>Selecting, editing and delete data using this control
>Handling the DataList control events
ASP.NET Handling the DataList control events


This chapter excerpt from ASP.NET Data Presentation Controls Essentials by Joydip Kanjilal, is printed with permission from Packt Publishing , Copyright 2007.

Handling Events

The Repeater, DataList, and DataGrid controls support event bubbling. What is event bubbling? Event Bubbling refers to the ability of a control to capture the events in a child control and bubble up the event to the container whenever an event occurs. The DataList control supports the following six events: 

ItemCreated
ItemCommand
EditCommand
UpdateCommand
DeleteCommand
CancelCommand

We will now discuss how we can work with the events of the DataList control. In order to handle events when working with a DataList control, include a Button or a LinkButton control in the DataList control. These controls have click events that can be used to bubble up the triggered event to the container control, that is, the DataList.

The following code snippet illustrates how you can attach a handler to an ItemCommand event of a DataList control:

<asp:DataList ID="DataList1" runat="server" onItemCommand = "ItemCommandEventHandler"/>

The corresponding handler that gets called whenever the event is fi red is as follows:

void ItemCommandEventHandler (Object src, DataListCommandEventArgs e ....)
{
      //Some event handling code
}

Simi larly, you can handle the ItemCreated event by specifying the handler in the .aspx file as follows:
<asp:DataList ID="DataList1" runat="server" onItemCreated = "ItemCreatedEventHandler" />

The corresponding handler that is triggered whenever this event occurs is as follows.

void ItemCreatedEventHandler ( Object src, DataListCommandEventArgs e )
{
       //Some event handling code     
}

Similarly, you can use the CancelCommand event by specifying the event handler in your .aspx file as follows:

<asp:DataList ID="DataList1" runat="server" onCancelCommand = .........."CancelCommandEventHandler" />

The corresponding handler that is triggered whenever this event occurs is as follows.

void ItemCreatedEventHandler ( Object src, DataListCommandEventArgs e )
{
        //Some event handling code
}

Similarly, you can use the CancelCommand event by specifying the event handler in your .aspx file as follows:

<asp:DataList ID="DataList1" runat="server" onCancelCommand = .........."CancelCommandEventHandler" />

The corresponding event handler that would get fi red is as follows:

void CancelCommandEventHandler ( Object src, DataListCommandEventArgs e )
{
      //Some event handling code
}

You can handle any of the other events similarly and execute your event handlers appropriately.



Write your comment - Share Knowledge and Experience


Also read

ASP.NET issues

The truth is that ASP.NET has several issues that need to be addressed.............

ASP.NET AJAX Advantages and History

With AJAX, only the necessary data is transferred back and forth between the client and the web server. This minimizes the network utilization and processing on the client...........

Technologies That Make Up AJAX

AJAX is a general umbrella term. AJAX itself stands for Asynchronous JavaScript And XML..........

What Is ASP.NET 2.0 AJAX?

ASP.NET 2.0 AJAX is an AJAX-oriented .NET library that runs on .NET 2.0. Though ASP.NET 2.0 AJAX is an AJAX library and can be used to perform AJAX operations, it is really much more. ASP.NET 2.0 AJAX offers many of the same types of features of the server-side ASP.NET............

The components in the ASP.NET 2.0 AJAX packaging

The packaging of ASP.NET 2.0 AJAX can be fairly confusing. The basics of the packaging are................

Explain how authorization works in ASP.NET

ASP.NET impersonation is controlled by entries in the applications web.config file...........

.NET crystal reports

How do we access crystal reports in .NET?
What are the various components in crystal reports?
What basic steps are needed to display a simple report in crystal?..........

 

Latest placement tests
Latest links
 
Latest MCQs
» General awareness - Banking » ASP.NET » PL/SQL » Mechanical Engineering
» IAS Prelims GS » Java » Programming Language » Electrical Engineering
» English » C++ » Software Engineering » Electronic Engineering
» Quantitative Aptitude » Oracle » English » Finance
Home | About us | Sitemap | Contact us | We are hiring