hi dear,
you have to put below code in the _ItemCreated Event of the dataGrid
/************************************************** */
protected void grd1_ItemCreated(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
TableCell preCell = null; // Last Row Cell
if (e.Item.ItemIndex > 0)
{
preCell = grd1.Items[e.Item.ItemIndex - 1].Cells[0];
}
if (preCell != null) // Our logic make sense when last row has any Cells!
{
TableCell cell = e.Item.Cells[0]; // Current Row Cell
if (preCell.Text == cell.Text)
{
if (preCell.Visible == false) // Row Span is already Started ....
{
//currentKeyCell contains current Key value Cell.
currentKeyCell.RowSpan = (currentKeyCell.RowSpan == 0 ? 1 : currentKeyCell.RowSpan) + 1;
}
else
{
//Set Last row Cell's RowSpan ..
preCell.RowSpan = (preCell.RowSpan == 0 ? 1 : preCell.RowSpan) + 1;
//Set New Key value Cell
currentKeyCell = preCell;
}
// Set Current Row Cell Visibility to false.
cell.Visible = false;
}
}
}
}
Jaiswar Vipin Kumar R. (India)
|