|
|
|
|
||||||||||||
Introduction
One of the rich in-built Webserver control is the DataGrid. We can do a lot with a DataGrid.
There are several ways, in which we can customize the datagrid according to our need. Assume
that we have a datagrid and we want to select any item (row) from the datagrid. How about
allowing the user to Double Click on anywhere on the DataGrid? When the user clicks, we
will retrieve the information of all columns of the selected row (double clicked row).
Things that we will be learning in this article
Populating the DataGridFor our example, we will take the table STORE in the PUBS Database. Since stored procedures are very much better than inline query, we use a stored procedure called, sp_stores_sel, which contains a single SQL statement. The SQL statement would be Select * pubs.dbo.from stores. What is OnItemDataBound Event and how it is invoked?
The ItemDataBound event is raised after an item is data bound to the DataGrid
control. This event provides you with the last opportunity to access the data item before
it is displayed on the client. So, this is the best place to add any events or to retrieve
any values that is being populated for the DataGrid. Inorder to invoke this event, we have
to specify while declaring a DataGrid such as: How to add an attribute OnDblClick to each row in the DataGrid?The output of DataGrid web server control is nothing but a HTML table. So, inorder to capture the double click event for each row, what we have to do is, add a double click event to each <tr> element in the DataGrid. Once the event added the <tr> tag should look like, <tr OnDblClick=ShowDetails();> How to retrieve the values for the row in which the user Double clicked?Retrieving the values for each row is very simple. All we have to do is to invoke the method, FindControl. We need to pass the name of each control (column) that we need to retrieve the values. Now let us take a look at the method, myItems_ItemDataBound. Code in the myItems_ItemDataBound method.
How it works?
In the above code, we have two variables. An instance of TableRow, and
a Label. Then we have a Select statement, since we need to create attributes for both
ItemStyles and AlternatingItemStyles. The statement, Sample output of our scenario
Download the code
Click here to download the ASPX page ConclusionThus we have discussed about how to capture the double click event in a datagrid. Links
DataGrid and Checkboxes Send your comments to das@aspalliance.com Back to Article list | ||||||||||||||
| Copyright © 2000-2003 ASPAlliance.com Page Rendered at
11/7/2009 8:22:40 PM |
||||||||||||||