473,379 Members | 1,167 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,379 software developers and data experts.

DataGrid footer to span columns?

Is it possible to create a DataGrid footer to span multiple columns?

Olav
Nov 19 '05 #1
1 2252
Olav,

The following is a snippet from the answer that Ken Cox gave on a similar
question. It should help you.

Dim dt As DataTable
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
DataGrid1.ShowHeader = True
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_ItemDataBound _
(ByVal sender As Object, _
ByVal e As _
System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemDataBound
' Have the first column header span
' two columns
' by Ken Cox Microsoft MVP [ASP.NET]
If e.Item.ItemType = ListItemType.Header Then
' Declare variables
Dim dgItem As DataGridItem
Dim tcells As TableCellCollection
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.ColumnSpan = 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.Remove(scell)
End If
End Sub
Function CreateDataSource() 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("Student", GetType(String)))
dt.Columns.Add(New DataColumn("Subject", 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>
--
Eliyahu
"Olav Tollefsen" <x@y.com> wrote in message
news:eQ*************@TK2MSFTNGP12.phx.gbl...
Is it possible to create a DataGrid footer to span multiple columns?

Olav

Nov 19 '05 #2

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

Similar topics

7
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...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
9
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ...
1
by: sri_san | last post by:
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...
1
by: needin4mation | last post by:
Hi I am trying to had a colspan to my footer. I have my DataGrid populating as normal. I then have a footer utilzed for the insert of new data. My DataGrid has an Edit Column and a Delete...
4
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...
2
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...
7
by: GaryDean | last post by:
I am writing a method in a component that gets passed a 1.1 Datagrid. The datagrid's columns were created at run time meaning it has no columns collection. How can I access Header and Footer...
5
by: tshad | last post by:
I have a datagrid that I cannot get to right justify a money amount (which is just a label). No matter what I do - it still right justifies it. <asp:TemplateColumn Visible="true"...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: 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...

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.