Results 1 to 3 of 3

Thread: Hardcoding a value in a datagrid footer [resolved]

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Hardcoding a value in a datagrid footer [resolved]

    I have a datagrid on a page, and this page is part of prototyping, entirely for display purposes.

    In the datagrid, I have set ShowFooter = "true".

    Now I'd like to place the text "something" in the footer, how can I do this through the HTML portion of the ASPX page and not through the codebehind?
    Last edited by mendhak; Apr 18th, 2005 at 08:36 AM.

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Hardcoding a value in a datagrid footer

    You'd have to assign the column definitions in the HTML too and then set the FooterText here.
    Code:
    <asp:DataGrid id="dgrd1" runat="server" ShowFooter="true">
    <Columns>
    <asp:BoundColumn HeaderText="Author" FooterText="Author" DataField="author" />
    </Columns>
    </asp:DataGrid>
    I think thats what you were asking anyway.

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Hardcoding a value in a datagrid footer

    I see what you mean. So if I have 4 columns, there'd be 4 column separators too.

    I tried this, and finally gave up and did this in the codebehind like so:

    VB Code:
    1. Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
    2.         ' else if (e.Item.ItemType == ListItemType.Footer) e.Item.Cells[2].Text = "<b>Total:</b> " + String.Format("{0:c}", runningSum);
    3.  
    4.         'If e.Item.ItemType = ListItemType.Footer Then
    5.         '    e.Item.Cells(e.Item.Cells.Count - 1).Text = "1"
    6.         'End If
    7.  
    8.  
    9.         If e.Item.ItemType = ListItemType.Footer Then
    10.             Dim numberofCells As Integer = e.Item.Cells.Count
    11.             Dim x As Integer
    12.             For x = 0 To numberofCells - 2
    13.                 e.Item.Cells.RemoveAt(0)
    14.             Next
    15.  
    16.             e.Item.Cells(0).Text = "1"
    17.             e.Item.Cells(0).ColumnSpan = numberofCells
    18.             e.Item.Cells(0).HorizontalAlign = HorizontalAlign.Center
    19.             e.Item.Cells(0).Attributes.Add("height", "100%")
    20.         End If
    21.  
    22.     End Sub

    Thanks for your time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width