Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Any way to reorder how a datagrid is drawn (header/footer/items vs.header/items/footer)?

Reply
Thread Tools

Any way to reorder how a datagrid is drawn (header/footer/items vs.header/items/footer)?

 
 
Henrik
Guest
Posts: n/a
 
      07-03-2006
Is there any way to reorder how a datagrid is drawn. I have a situation
where it is preferred to have the footer show up before the already
existing data rows. My footer is being used for adding new rows.

Current/default ordering:

Header
Item1
Item2
Item3
Footer

Desired ordering:

Header
Footer (new record entry)
Item1
Item2
Item3
 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      07-06-2006
Hi Henrik,

Here's a way to manipulate the footer. See if it works for you?

Ken
Microsoft MVP [ASP.NET]

<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not IsPostBack Then
Datagrid1.DataSource = CreateDataSource()
Datagrid1.DataBind()
End If
End Sub

Private Sub DataGrid1_ItemDataBound _
(ByVal sender As Object, _
ByVal e As _
System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles Datagrid1.ItemDataBound
' Simulates a move of the footer to the second line
' Ken Cox [MVP] - July 5/06
' Check if this is the footer
If e.Item.ItemType = ListItemType.Footer Then
' Create a new footer item
Dim dgItemFooter As New DataGridItem(0, 0, ListItemType.Footer)
Dim intCount As Integer
Dim tcells As TableCellCollection
Dim fcell As TableCell
' Get a reference to the original footer cells
tcells = e.Item.Cells
' Loop through the original cells
For intCount = 0 To tcells.Count - 1
fcell = New TableCell
' Get the text from the original cell
fcell.Text = tcells(intCount).Text
' Add the cell to the new 'footer'
dgItemFooter.Cells.Add(fcell)
Next
' Insert the new footer into the datagrid
Datagrid1.Controls(0).Controls.AddAt(2, dgItemFooter)
' Remove the original footer
Datagrid1.Controls(0).Controls.Remove(e.Item)
End If
End Sub


Function CreateDataSource() As Data.DataTable
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
dt.Columns.Add(New Data.DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New Data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New Data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New Data.DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 5
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Move the footer</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="Datagrid1" runat="server" allowpaging="True"
showfooter="True">
</asp:datagrid>
</div>
</form>
</body>
</html>

"Henrik" <> wrote in message
news:%...
> Is there any way to reorder how a datagrid is drawn. I have a situation
> where it is preferred to have the footer show up before the already
> existing data rows. My footer is being used for adding new rows.
>
> Current/default ordering:
>
> Header
> Item1
> Item2
> Item3
> Footer
>
> Desired ordering:
>
> Header
> Footer (new record entry)
> Item1
> Item2
> Item3



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
Background Image on Button control does not get drawn under Windows XP. Ken Varn ASP .Net 0 11-12-2004 09:25 PM
Title in forms drawn by showModalDialog Jim Brandley ASP .Net 1 06-30-2004 07:01 PM
ensuring that all declared controls have been drawn David ASP .Net 0 05-02-2004 09:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57