473,802 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datagrid - Header span over multiple columns

Hello,
I have a datagrid in which the header needs to span over 2
columns. I have tried creating a tableCells and tableRow at runtime and
set the columnspan property of a cell to 2. But, the heading does not
look good and is not aligned to the datagrid columns. Is there another
way to do it?
Any help would be great!!

Thanks,
Sam.

Nov 19 '05 #1
1 3449
Hi Sam,

Here's some code that should get you going on this. Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

Dim dt As DataTable
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles MyBase.Load
DataGrid1.ShowH eader = True
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End Sub
Private Sub DataGrid1_ItemD ataBound _
(ByVal sender As Object, _
ByVal e As _
System.Web.UI.W ebControls.Data GridItemEventAr gs) _
Handles DataGrid1.ItemD ataBound
' Have the first column header span
' two columns
' by Ken Cox Microsoft MVP [ASP.NET]
If e.Item.ItemType = ListItemType.He ader Then
' Declare variables
Dim dgItem As DataGridItem
Dim tcells As TableCellCollec tion
Dim fcell As TableCell
Dim scell As TableCell
' Get a reference to the header row item
dgItem = e.Item
' Get a reference to the cells in the
' header row item
tcells = e.Item.Cells
' Get a reference to the cell we want to
' span. In this case, the first cell
fcell = e.Item.Cells(0)
' Set the text of the span cell
fcell.Text = "This is the spanned cell"
' Set the columns to span to 2
fcell.ColumnSpa n = 2
' Get a reference to the second cell
scell = e.Item.Cells(1)
' Remove the second cell because it will
' be replaced by the spanning column
dgItem.Cells.Re move(scell)
End If
End Sub
Function CreateDataSourc e() As ICollection
' Create sample data for the DataList control.
dt = New DataTable
Dim dr As DataRow

' Define the columns of the table.
dt.Columns.Add( New DataColumn("Stu dent", GetType(String) ))
dt.Columns.Add( New DataColumn("Sub ject", GetType(String) ))
dt.Columns.Add( New DataColumn("Day ", GetType(String) ))

' Populate the table with sample values.
dr = dt.NewRow
dr(0) = "Ben"
dr(1) = "English"
dr(2) = "Thursday"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(0) = "Ben"
dr(1) = "Geology"
dr(2) = "Monday"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(0) = "Ben"
dr(1) = "Physics"
dr(2) = "Tuesday"
dt.Rows.Add(dr)
Dim dv As DataView = New DataView(dt)
Return dv
End Function

<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server"> </asp:DataGrid>
</form>

<sr*****@mailci ty.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.com.. .
Hello,
I have a datagrid in which the header needs to span over 2
columns. I have tried creating a tableCells and tableRow at runtime and
set the columnspan property of a cell to 2. But, the heading does not
look good and is not aligned to the datagrid columns. Is there another
way to do it?
Any help would be great!!

Thanks,
Sam.


Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
7701
by: Billy Jacobs | last post by:
I am using a datagrid to display some data. I need to create 2 header rows for this grid with columns of varying spans. In html it would be the following. <Table> <tr> <td colspan=8>Official Impact Summary</td> </tr> <tr> <td colspan=2></td>
6
38292
by: Chuck | last post by:
I have a report with three columns, accross then down, and two groups. Currently the group headers are only one column wide and appear in the left hand column. How can I make the group header be centered accross all columns? Chuck ....
8
1793
by: Alejandro Penate-Diaz | last post by:
I have a datagrid inside a table and I want to fix both (table and databrid) width to 700, but when the content of datagrid is too large the width increases automatically sometimes and sometimes not. Please need help with that. Thanks, Alejandro.
1
2279
by: Olav Tollefsen | last post by:
Is it possible to create a DataGrid footer to span multiple columns? Olav
2
6415
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
6
2193
by: tshad | last post by:
I have a datagrid where each column has both a label and a linkbutton. I need to have the label left justified and the linkbutton right justified. In HTML, I would have to set up 2 cells to do this. Is there a way to accomplish this in a DataGrid (and have the text span both columns). What I have is:
4
4727
by: Mortar | last post by:
i need a datagrid with 2 header columns. The top one might have 1 column spanning 5 columns of the header row below it. what is the best way to do this? Could i have 2 datatables...1 filling the top row, and the 2nd header row would come from the 2nd datatable? In this case, i guess i would have to add a row manually above the header row (2nd dataset) which is the set of 1st data? if someone has ideas, code explaining it would be very...
1
1256
by: Dave | last post by:
Hi, I'm trying to use templated columns to format the header for my datagrid. Can I use the HeaderTemplate to make the "My Title Goes.." text to span across the entire datagrid table when it's generated? Or some other method? Thanks. <asp:DataGrid ID="dgList" AutoGenerateColumns=False Runat=server> <Columns> <asp:TemplateColumn > <HeaderTemplate>My Title Goes Here.</HeaderTemplate> </asp:TemplateColumn>
2
3444
by: Mike Baugh | last post by:
I am using visual studio 2005 to develop a form using c# I have 3 datagrids on one form. I can set the row color based on a certain value in a column. However this color applies to all 3 datagrida. I would like to set it so that if value of column 3 in datagrid 1 is < 100 set to red, if = 100 set to green if value of column 3 in datagrid 2 is < 90 set to red, if >= 90 set to green if value of column 3 in datagrid 3is < 80 set to red,...
0
10538
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10305
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.