|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
I have been looking for a way to add headers to a grid view and to be able to re use this code this code snippet could help adding the headers to grid view
The Method that Dose the work: Demo solution Downlod Download sourcecode Description: Gridview comes with a header for each column, you can't have an extra header to your Gridview, we can use the caption to some HTML tags and start building the extra headers, for me I did not like this solution, and came up with this code snippet This method checks if the row of type header r then adds a row to the Gridview of type header by creating an object of type GridViewRow : row = new GridViewRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal); to add the celss I Declaird an IDictionaryEnumerator that will count the cells passed by a sorted list , then within the sorted list I creat an arry of strings that ill be used to set the cells properties , an d last adding the Cells to the row IDictionaryEnumerator enumCels = GetCels.GetEnumerator(); /// <summary> /// Gets my multi header. /// </summary> /// <param name="e">The <see cref="T:System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param> /// <param name="GetCels">The get cels. is sorted list that contain the cells the key is the position of the cell and the valu is a comma delemeted /// data to hold the cell information , index 0 is for the Content of the cell m index 1 is the coms span , index 2 is the row span /// pleas dont leav the colmn span and rowspan empty</param> public void GetMyMultiHeader(GridViewRowEventArgs e, SortedList GetCels) {
if (e.Row.RowType == DataControlRowType.Header)
{
How to use the methode we have to use a sorted list as so the key of the sorted list is the cell position , and the contetn of the sell is the valu with a comma delemeted the first index is the text , the next index is the colmn span , and the 3ed index is the row span like this example
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||