Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 2nd, 2006, 06:06 AM
Registered User
Join Date: Apr 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using Rowspan in datagrid


Got a problem.

Actually i have a data like the following

1 cat1 subcat1 rate1
2 subcat2 rate2
3 subcat3 rate3
4 subcat4 rate4
5 cat2 subcat1 rate1
6 subcat2 rate1
7 cat3 subcat1 rate1

Can i put it in a datgrid in the same way.
I don't want the category (2nd column) to get repeated in all the rows.

Can this be worked out through rowspan?

thanks for the help..

Old January 28th, 2008, 07:28 AM
Registered User
Join Date: Jan 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jaiswarvipin Send a message via Yahoo to jaiswarvipin

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;
//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)
Old February 15th, 2008, 03:21 AM
Authorized User
Join Date: Jan 2008
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts

hi Jaiswar,

   i saw your post. i think it's interesting. if you don't mind can you please provide the explanation or comments of your given code.i want to know what does the following code do. if you could provide comments beside your code, it will be the best way to get understand.

Thank you
.Net Consulting

Similar Threads
Thread Thread Starter Forum Replies Last Post
Filling the gaps of rowspan/colspan sources maikm XSLT 3 August 27th, 2008 03:36 AM
Gridview Rowspan and ColumnSpan ramuis78 ASP.NET 2.0 Professional 3 June 25th, 2007 09:29 PM
RowSpan not working like I thought MLaGrange ASP.NET 2.0 Basics 0 February 20th, 2006 10:13 AM
RowSpan tgopal Javascript 6 September 28th, 2004 03:35 AM
ROWSPAN PROBLEM saravananedu HTML Code Clinic 3 July 27th, 2004 03:58 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.