473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Merge cells in datagrid (.NET 1.1)

codesid
Just to add the info in this community that I finally found a way to merge cells in a datagrid. In many other forums over the Internet we hear many different opinions, usually asking you to move to ASP.NET 2.0. For those still struggling in 1.1, this is a way out:

When you bind the dataset in the datagrd, it creates an event that you can use to change the way the data will be binded to it. In the InitializeComponent(), add the code:

private void InitializeComponent()
{
// ... there will be more code here

this.MyDataGrid.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler (this.MyDataGrid_ItemDataBoundEventHandler);
}

where the MyDataGrid is my datagrid object.

Then, this event will be handled at:

private void MyDataGrid_ItemDataBoundEventHandler(object sender, DataGridItemEventArgs e)
{
switch(e.Item.ItemType)
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
e.Item.Cells[0].ColumnSpan = 2;
e.Item.Cells[1].Visible = false;
break;
}

}

This code above will be executed for every row. For the ones you want to specify the colspan (merge) or not, just handle it with a if else condition statement. It works just fine!

Happy programming!
Feb 14 '07 #1
1 5760
enreil
86
Thanks for the tip!

Just to add the info in this community that I finally found a way to merge cells in a datagrid. In many other forums over the Internet we hear many different opinions, usually asking you to move to ASP.NET 2.0. For those still struggling in 1.1, this is a way out:

When you bind the dataset in the datagrd, it creates an event that you can use to change the way the data will be binded to it. In the InitializeComponent(), add the code:

private void InitializeComponent()
{
// ... there will be more code here

this.MyDataGrid.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler (this.MyDataGrid_ItemDataBoundEventHandler);
}

where the MyDataGrid is my datagrid object.

Then, this event will be handled at:

private void MyDataGrid_ItemDataBoundEventHandler(object sender, DataGridItemEventArgs e)
{
switch(e.Item.ItemType)
{
case ListItemType.Item:
case ListItemType.AlternatingItem:
e.Item.Cells[0].ColumnSpan = 2;
e.Item.Cells[1].Visible = false;
break;
}

}

This code above will be executed for every row. For the ones you want to specify the colspan (merge) or not, just handle it with a if else condition statement. It works just fine!

Happy programming!
Feb 14 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Steve Donnor | last post by:
Here's my question.. I have a Dataset which has populated a datagrid with information from an AS400 That SQL looks like this "Select MASYS, MAFLD, MADATA, MAEQV from QS36F.MAPDATA WHERE MASYS =...
5
by: Ariel Gimenez | last post by:
Morning! After several hours breaking my mind, finally my code works, but i think is trash-code, can someone tellme how is the correct way to access the value of my cells within a datagrid?... in...
1
by: Peter Zausch | last post by:
Hello, is it possible to merge cells in a datagrid ? In the MS Flexgrid it was possible if cells have the same content. In the datarid i did not found any corresponding function. Regards ...
4
by: EMW | last post by:
For my ASP.NET program I want to use the datagrid as a sort of planning tool. Based on the information in a XML file, a cell of the datagrid must show an image... Well, this is what I would...
1
by: Mark Goldin | last post by:
How do I merge cells in a table? I am selecting two cells, but Merge cells is disasbled in a Popup menu.
3
by: tshad | last post by:
How do I get blank cells to show in my dataGrid? I am databinding to my datagrid, but any cells that are blank, don't show. Normally, you would put an &nbsp in the cell to make IE display the...
0
by: cwbp17 | last post by:
I'm having trouble updating individual datagrid cells. Have two tables car_master (columns include Car_ID, YEAR,VEHICLE) and car_detail (columns include Car_ID,PRICE,MILEAGE,and BODY);both tables...
2
by: Benny Ng | last post by:
Dear All, Now i have a two dataset. they have same db structure and same columns and same rows. just the content is not same between them. for example: datagrid 1:
1
by: rytsyd | last post by:
Hi, I already have a working code where I have an application that queries to SQL then exports it to excel. It also merge cells that have the same value. The only problem I have is that it takes...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.