|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis control is an extension to the ASP.NET
BenefitLet me explain to you the importance of these enhancements in a grid control by examining the time taken to implement these very common functionalities in a single grid control.
In short, for a single gird, we can save at least 6 hrs., with comparatively lesser error chances and better performance. This also reduces the overall testing effort. In such a way, we can save about 6000 hrs in a 1000 pages distributed application. MotivationIn the previous 8 months, during office hours, I was getting sick of doing the above tasks on data grids again and again. All my colleagues were doing the same till now, and were quite alright with this reinventing the wheel practice, but I am not a guy who is happy with this kind of down and dirty work. We (software developers) are usually bound to work in hurry and worry. So, I decided to take over, as I got some free Saturdays, thus I started working on this to give my fellows a broader vision of re usability and .NET. Implementation and how to useClient side sortingThe [ToolboxData("<{0}:DataGrid runat="\""server\" />")]
public class DataGrid : System.Web.UI.WebControls.DataGrid
{
public DataGrid() : base()
{
}
•••
}
Capture the default HTML markup and parse it. The StringWriter writer = new StringWriter();
HtmlTextWriter buffer = new HtmlTextWriter(writer);
base.Render(buffer);
string gridMarkup = writer.ToString();
Finally, write the modified markup to the response stream. Any additional attributes can be added here for displaying in the HTML. This is the way you can change the look n feel and behavior of any ASP.NET control according to your will. I have modified the HTML, and formatted it in a more structured HTML table having How to do sortingThe following properties need to be set for enabling client-side sorting of the grid.
Column draggingTo do this, we need to write a kind of DHTML behavior so that we can reuse it over and again. You can go through the wonderful "DHTML Dude" column on MSDN® Online. It discusses ways to revive the HTML table element and how to drag columns around. For more details on DHTM components, please see: Scripting Evolves to a More Powerful Technology: HTML Behaviors in Depth. Again, you need to do the same practice as were for the sort and just need to modify the generated HTML and add a behavior to the table, and that is it. Now, your modified style="behavior:behavior:url(dragdrop.htc);"
How to use column dragging
Custom selection columnFor the implementation details of this custom column, you can have a look at one of my previous posts: [Implementing Custom Selection Column], or you can visit my blog for this. All the row selection color, check all, and uncheck all functionalities are built into that column. To add a selection column with check all, uncheck all, and row selection color, you need to add the reference of the assembly in your page that contains the <Columns> <cc1:CheckBoxColumn\> </Columns>
You can optionally bind this column with a data source by specifying the <Columns>
<cc1:CheckBoxColumn RowSelectColor="Wheat" RowUnSelectColor="White" \>
</Columns>
Fixed headerYou need to add a document type at the top of your aspx page, as follows: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Everything else will be handled by the custom grid. RemainingIn part two, I will discuss and implement the remaining features. ConclusionThis nifty control can save you hours that were used for common formatting, repetitive scripting, and coding by just dragging this control on the page.
|
||||||||||||||||||||||