Monday, August 10, 2009

GridView MultiHeader

**********************************************************************************
소스
**********************************************************************************
#region Refactoring the MultiHeader
///
/// Gets my multi header.
///

/// The instance containing the event data.
/// 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
public static void GetMyMultiHeader(GridViewRowEventArgs e, SortedList GetCels)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridViewRow row;
IDictionaryEnumerator enumCels = GetCels.GetEnumerator();

row = new GridViewRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal);
while (enumCels.MoveNext())
{

string[] cont = enumCels.Value.ToString().Split(Convert.ToChar(","));
TableCell Cell;
Cell = new TableCell();
Cell.RowSpan = Convert.ToInt16(cont[2].ToString());
Cell.ColumnSpan = Convert.ToInt16(cont[1].ToString());
Cell.Controls.Add(new LiteralControl(cont[0].ToString()));
Cell.HorizontalAlign = HorizontalAlign.Center;
Cell.ForeColor = System.Drawing.Color.Black;
row.Cells.Add(Cell);
}

e.Row.Parent.Controls.AddAt(0, row);
}
}
#endregion

**********************************************************************************
사용 예시
**********************************************************************************
SortedList creatCels = new SortedList();

creatCels.Add("1", "이벤트 접속,2,1");
creatCels.Add("2", ",1,1");
creatCels.Add("3", "SMS,2,1");
creatCels.Add("4", "접속,4,1");
creatCels.Add("6", "다운시도,3,1");

Comm.GridView.GetMyMultiHeader(e, creatCels);

SortedList creatCels2 = new SortedList();

creatCels2.Add("1", ",4,2");
creatCels2.Add("2", "WEB,5,1");
creatCels2.Add("3", "WAP,7,1");
creatCels2.Add("4", "APP,1,2");
creatCels2.Add("5", ",1,2");

Comm.GridView.GetMyMultiHeader(e, creatCels2);