DataGrid footer to span columns?

Discussion in 'ASP .Net' started by Olav Tollefsen, Jan 31, 2005.

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

    Olav
    Olav Tollefsen, Jan 31, 2005
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > Is it possible to create a DataGrid footer to span multiple columns?
    >
    > Olav
    >
    >
    Eliyahu Goldin, Jan 31, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fulio Open

    Can span include span?

    Fulio Open, Jun 26, 2009, in forum: HTML
    Replies:
    5
    Views:
    546
    dorayme
    Jun 26, 2009
  2. Stéphane Klein
    Replies:
    2
    Views:
    1,757
    John Nagle
    Mar 30, 2010
  3. Stefan Behnel
    Replies:
    0
    Views:
    486
    Stefan Behnel
    Mar 29, 2010
  4. Dan Bishop

    DataGrid (body only) contained in <span>...</span> tags

    Dan Bishop, Jun 7, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    277
    Kilic Beg
    Jun 7, 2004
  5. Henrik
    Replies:
    1
    Views:
    423
    Ken Cox [Microsoft MVP]
    Jul 6, 2006
Loading...

Share This Page