Book Excerpt: Working with the DataList Control
In this chapter, we will cover the ASP.NET DataList control. We will learn about
the following:
|
|
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.
Also read
The truth is that ASP.NET has several issues that need to be
addressed.............
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...........
AJAX is a general umbrella term. AJAX itself stands for Asynchronous JavaScript
And XML..........
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 packaging of ASP.NET 2.0 AJAX can be fairly confusing. The basics of the
packaging are................
ASP.NET impersonation is controlled by entries in the applications web.config
file...........
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?..........
|