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?
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
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:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
' else if (e.Item.ItemType == ListItemType.Footer) e.Item.Cells[2].Text = "<b>Total:</b> " + String.Format("{0:c}", runningSum);
'If e.Item.ItemType = ListItemType.Footer Then
' e.Item.Cells(e.Item.Cells.Count - 1).Text = "1"
'End If
If e.Item.ItemType = ListItemType.Footer Then
Dim numberofCells As Integer = e.Item.Cells.Count
Dim x As Integer
For x = 0 To numberofCells - 2
e.Item.Cells.RemoveAt(0)
Next
e.Item.Cells(0).Text = "1"
e.Item.Cells(0).ColumnSpan = numberofCells
e.Item.Cells(0).HorizontalAlign = HorizontalAlign.Center
e.Item.Cells(0).Attributes.Add("height", "100%")
End If
End Sub
Thanks for your time.