Introduction
It is a cool asp.net DataGrid Merger, it is very simple and useful.
Only use a few code, you can merge datagrid's Header and body.
I hope it is helpful to you!
Using the code
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
AddTableColumn(dt, "f1", null);
AddTableColumn(dt, "f2", "income|f2");
AddTableColumn(dt, "f3", "income|f3");
AddTableColumn(dt, "f4", "income|Last Year|f4");
AddTableColumn(dt, "f5", "income|Last Year|f5");
AddTableColumn(dt, "f6", null);
AddTableColumn(dt, "f7", "outcome|f7");
AddTableColumn(dt, "f8", "outcome|f9");
for (int r = 1; r <= 6; r++)
{
DataRow dr = dt.NewRow();
dr["f1"] = "" + (r / 4);
dr["f2"] = "" + (r / 2);
for (int col = 3; col <= dt.Columns.Count; col++)
dr["f" + col] = "" + (col*r);
dt.Rows.Add(dr);
}
DataGrid1.DataSource = dt;
foreach (DataColumn dataColumn in dt.Columns)
{
BoundColumn column = new BoundColumn();
column.DataField = dataColumn.ColumnName;
column.HeaderText = dataColumn.Caption == null ? dataColumn.ColumnName : dataColumn.Caption;
DataGrid1.Columns.Add(column);
}
DfawWeb.CtrlUtil.DataGridMerger merger = new DfawWeb.CtrlUtil.DataGridMerger(DataGrid1);
merger.AddMergeColumn("f2");
merger.AddMergeColumn("f1");
DataBind();
}
public interface IMatrix
{
int RowCount { get; }
int ColumnCount { get; }
object GetCellValue(int row, int col);
}
public class MergeCell
{
public System.Drawing.Rectangle Bounds;
public object Value;
}
public class MergeCellList : CollectionBase
{
public enum MergeModeEnum
{
RowCol = 0,
Col,
Row
}
...
}
void dataGrid_ItemCreated(object sender, DataGridItemEventArgs e)
{
if (ListItemType.Item == e.Item.ItemType || ListItemType.AlternatingItem == e.Item.ItemType)
{
if (canMergColHash != null && canMergColHash.Count > 0)
e.Item.SetRenderMethodDelegate(new RenderMethod(BodyMergeRenderMethod));
return;
}
if (cellList != null && ListItemType.Header == e.Item.ItemType)
e.Item.SetRenderMethodDelegate(new RenderMethod(HeaderMergeRenderMethod));
}
Points of Interest
more know, please Visit: http://www.longxsoft.com/