Cheap Hosting Domain Names

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 7 May 2012

ItemDataBound in ASP.NET

Posted on 07:16 by Unknown

The ItemDataBound event is raised after an item or row 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. After this event is raised, the data item is nulled out and no longer available.

Within the method, we check if the current row is a header or a footer row.To do this we use ListItemType enumeration. ListItemType enumeration contains different types of items(header, footer, item, alternating item etc.)

To identify Header: if (e.Item.ItemType == ListItemType.Header)
To identify Footer: if (e.Item.ItemType == ListItemType.Footer)
To identify Item: if (e.Item.ItemType == ListItemType.Item)
To identify AlternatingItem: if (e.Item.ItemType == ListItemType.AlternatingItem)


ItemDataBound Function can be used for various functionalities:

How to hide any column of a particular row of a DataGrid?

procedure TClassName.dgrDataGrid_ItemDataBound(sender: System.Object; e: System.Web.UI.WebControls.DataGridItemEventArgs);
begin
   e.Item.Cells[‘ColumnName’].Attributes.Add('style','display:none');
end;


How to change contents of any column of a particular row of a DataGrid?

procedure TClassName.dgrDataGrid_ItemDataBound(sender: System.Object; e: System.Web.UI.WebControls.DataGridItemEventArgs);
begin
    if (e.item.ItemType =  listItemType.Item) or (e.item.ItemType =  listItemType.AlternatingItem) then
    begin
        if (e.Item.Cells[‘ColumnName’].Text = 'ABC') then e.Item.Cells[‘ColumnName’].Text := 'XYZ';
    end;
end;


How to change background color a particular row of a DataGrid?

procedure TClassName.dgrDataGrid_ItemDataBound(sender: System.Object; e: System.Web.UI.WebControls.DataGridItemEventArgs);
begin
    if (e.item.ItemType =  listItemType.Item) or (e.item.ItemType =  listItemType.AlternatingItem) then
    begin
        e.Item.Style['background'] := 'AliceBlue';                                  
        e.Item.Attributes.Item['OrigBackColor'] := 'AliceBlue'; //To retain the previous background color of the row
        //e.Item.BackColor := System.Drawing.Color.AliceBlue; This is the other way to color the background of the row.
    end;
end;


How to add javascript functions on each row of a DataGrid?

procedure TClassName.dgrDataGrid_ItemDataBound(sender: System.Object; e: System.Web.UI.WebControls.DataGridItemEventArgs);
begin
     if (e.item.ItemType =  listItemType.Item) or (e.item.ItemType =  listItemType.AlternatingItem) then
    begin
        e.Item.Attributes.Add('onselectstart', 'return OnSelectStartFunction();');
        e.Item.Attributes.Add('onclick',' return OnClickFunction();');
        e.Item.Attributes.Add('ondblclick',' return OnDoubleClickFunction();');
        e.Item.Attributes.Add('onmouseover','changeStyle();');
    end;
end;


In this way, you can use itemdatabound function to perform a lot of functionalities.
Email ThisBlogThis!Share to XShare to Facebook
Posted in DOTNET | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Online Religion Degrees
    Religion plays a major role in the historical, political, and cultural life of our societies. If you are fascinated by belief systems, consi...
  • How to create dynamic tables in HTML using javascript at runtime?
    In this tutorial, you will come to know how to create dynamic tables in HTML. There are some situations when you don't know the contents...
  • Online Economics Degrees
    Economists research and analyze economics, or the way people choose to use their resources to produce goods and services. Economists typical...
  • Online Advertising Degrees
    The objective of any business firm is to market and sell its products or services profitably. In small firms, the owner or chief executive o...
  • Online Geography Degrees
    With the growth of online colleges and universities, geography degrees online have gained immense importance. Geography degrees online can b...
  • Online DBA (Database Administrator) Degrees
    Database managers keep vital information organized.  With a database technology degree, you may find yourself organizing customer informatio...
  • Online Social Science Degrees
    Social science covers a broad range of fields: behavioral science, history, economics, geography, political science, women''s studie...
  • Difference between page_init, page_load and page_prerender events
    page_init This event is the first event to occur when an ASP.NET page is executed. This is the event where you should be performing any init...
  • Online BCA Degrees
    The boom in the IT industry has opened up plenty of job opportunities for computer professionals. As a result, computer application courses ...
  • Online Professional Degrees
    Going back to get more education can be a difficult, time consuming and sometimes impossible proposition. But with new advances in virtual t...

Categories

  • AJAX
  • C++
  • CSS
  • Delphi
  • DOTNET
  • HTML
  • Javascript
  • jQuery
  • Management
  • Online Degrees
  • Oracle
  • Others
  • Phonegap
  • PHP
  • Unix
  • XML

Blog Archive

  • ▼  2012 (180)
    • ►  September (89)
    • ►  August (11)
    • ►  July (4)
    • ►  June (3)
    • ▼  May (25)
      • Positioning Property and Z-Index in CSS
      • Validation Controls in ASP.NET: System.Web.UI.WebC...
      • COM Family: COM+ and DCOM, Interop, RPC and TLB
      • Frameset, Frame and IFrame Elements in HTML
      • List of problems occuring while using html tables
      • Alternative of XML: JSON (JavaScript Object Notation)
      • Basic Points of SOA (Service Oriented Architecture)
      • 11 Commonly used AJAX Frameworks
      • WCF: A SOA based Service Framework
      • WPF (Windows Presentation Foundation): Features
      • Relation between Tablespace, Datafile and Control ...
      • 6 Advantages of using stored procedures in your ap...
      • Window Object in Javascript: Properties and Methods
      • DECODE Function vs CASE Statement in Oracle
      • Oracle Streams: An Overview
      • Network Configuration Files in Oracle
      • 40 Objective Type ASP.NET Interview Questions (Par...
      • SQL Replay: A new feature of Oracle 11g
      • 11 Methods to implement 301 Redirect URLs
      • Partitioned Tables: Types and Advantages
      • ItemDataBound in ASP.NET
      • Protecting E-mail Addresses on Webpages: Beware of...
      • Non Breaking Space vs Zero Width Space in HTML
      • Difference between AJAX and jQuery
      • Preloading Images: A trick to overcome delays in i...
    • ►  April (48)
Powered by Blogger.

About Me

Unknown
View my complete profile