datagrid w/ 2 headers

F

Freddie

hi, can u plz give me an advice or link on how to implement a table w/ 2
row header - something like

abc
zxc | qwe | asd
1 | 2 | 3
34 | 232| 234

i need to be able to sort by both headers

the project uses asp.net 1.1

TIA
 
K

Ken Cox [Microsoft MVP]

Hi Freddie,

Here's an example that might give you the idea.

Let us know if it helps?

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">
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
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
If e.Item.ItemType = ListItemType.Header Then
Dim dgItemHeader As New DataGridItem _
(0, 0, ListItemType.Header)
Dim intCount As Integer
Dim tcells As TableCellCollection
tcells = e.Item.Cells
Dim fcell As TableCell
Dim blnToggle As Boolean
For intCount = 0 To tcells.Count - 1
fcell = New TableCell
blnToggle = Not blnToggle
If blnToggle Then
fcell.Text = tcells(intCount).Text
tcells(intCount).Text = ""
Else
fcell.Text = ""
End If
dgItemHeader.Cells.Add(fcell)
Next
DataGrid1.Controls(0).Controls.Add(dgItemHeader)
End If
End Sub


Function CreateDataSource() As System.Data.DataTable
Dim dt As New System.Data.DataTable
Dim dr As System.Data.DataRow
dt.Columns.Add(New System.Data.DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New System.Data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New System.Data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New System.Data.DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
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 'CreateDataSource


</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="DataGrid1" runat="server"
autogeneratecolumns="False">
<columns>
<asp:boundcolumn datafield="StringValue"
headertext="String
Value"></asp:boundcolumn>
<asp:boundcolumn datafield="IntegerValue"
headertext="Integer
Value"></asp:boundcolumn>
<asp:boundcolumn datafield="Boolean"
headertext="Boolean"></asp:boundcolumn>
<asp:boundcolumn datafield="CurrencyValue"
headertext="Currency
Value"></asp:boundcolumn>
</columns>
</asp:datagrid>
</div>
</form>
</body>
</html>
 
F

Freddie

hehe
works great

tnx, Ken
Hi Freddie,

Here's an example that might give you the idea.

Let us know if it helps?

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">
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
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
If e.Item.ItemType = ListItemType.Header Then
Dim dgItemHeader As New DataGridItem _
(0, 0, ListItemType.Header)
Dim intCount As Integer
Dim tcells As TableCellCollection
tcells = e.Item.Cells
Dim fcell As TableCell
Dim blnToggle As Boolean
For intCount = 0 To tcells.Count - 1
fcell = New TableCell
blnToggle = Not blnToggle
If blnToggle Then
fcell.Text = tcells(intCount).Text
tcells(intCount).Text = ""
Else
fcell.Text = ""
End If
dgItemHeader.Cells.Add(fcell)
Next
DataGrid1.Controls(0).Controls.Add(dgItemHeader)
End If
End Sub


Function CreateDataSource() As System.Data.DataTable
Dim dt As New System.Data.DataTable
Dim dr As System.Data.DataRow
dt.Columns.Add(New System.Data.DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New System.Data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New System.Data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New System.Data.DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
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 'CreateDataSource


</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="DataGrid1" runat="server"
autogeneratecolumns="False">
<columns>
<asp:boundcolumn datafield="StringValue"
headertext="String
Value"></asp:boundcolumn>
<asp:boundcolumn datafield="IntegerValue"
headertext="Integer
Value"></asp:boundcolumn>
<asp:boundcolumn datafield="Boolean"
headertext="Boolean"></asp:boundcolumn>
<asp:boundcolumn datafield="CurrencyValue"
headertext="Currency
Value"></asp:boundcolumn>
</columns>
</asp:datagrid>
</div>
</form>
</body>
</html>

hi, can u plz give me an advice or link on how to implement a table w/ 2
row header - something like

abc
zxc | qwe | asd
1 | 2 | 3
34 | 232| 234

i need to be able to sort by both headers

the project uses asp.net 1.1

TIA
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,294
Latest member
LandonPigo

Latest Threads

Top