Custom DataGrid Column: Custom DataGrid BoundColumn that automatically shows Sum/Average in DataGrid Footer. And Assigning Custom Data Type in DataField.






1.84/5 (6 votes)
Feb 14, 2007
9 min read

35643

296
I want to show the sample which you can find custom design of your bound column of datagrid. Generally our basic requirement is the sum and average of the value in footer with great performance. here I have created one more custom column where I am assignning custom datatype.
Download source code - 20.9 KbIntroduction:
Background:
DataGrid DataItemBound event :Here I set up a simple DataGrid that displays the EmpID, Name and Salary from Employee Table.
|
|
|
|
And in the code behind:
|
|
|
|
|
|
|
|
Simply I have created one employee class to keep employee information: "Employee.cs"
|
|
I have created one SumColumn class which is inherited from the BoundColumn class as "SumColumn.cs": |
|
|
|
And also I have created one AddressColumn class, derived from BoundColumn class to customize my address as follows with class name "AddressColumn.cs":
|
|
My Aspx page is like this: Here in item template i am calling a function "ConcatnatFirstNameLastName(string,string)" which will concatnate employee first name and employee last name and gives employee name. this function is defined in code behind of aspx page and it's access modifier is protected, private cannot be access | |
|
|
And in the code behind, we would do in the page load event like below: |
|
|
|
The above example DataClass is nothing but a class which creates a dummy data of employee and GetEmpInfo() method returns a arraylist containing the employee records. I think that the above code is quite self explanatory Conclusion:In this small example I tried to show you how to customize our datagrid column according to our requirement with good structured manner and also a good performance. That is why I have given here three different example with three different column "EmpName" which shows the employee name with concatenating the first name and last name of employee, "Age" and "Salary" which are achieved by Our own new custom column SumColumn derived from BoundColumn having the functionality of showing the sum/average of values of the column in the footer of the DataGrid. This is just one example of a reusable DataGrid column and it is up to you to examine your own applications and find out what could be neatly wrapped up into a custom DataGrid column. Note
References:
|