473,386 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

datagrid w/ 2 headers

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
Jul 14 '06 #1
2 1118
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>

"Freddie" <su**@spam.comwrote in message
news:ud**************@TK2MSFTNGP04.phx.gbl...
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

Jul 15 '06 #2
hehe
works great

tnx, Ken

Ken Cox [Microsoft MVP] wrote:
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>

"Freddie" <su**@spam.comwrote in message
news:ud**************@TK2MSFTNGP04.phx.gbl...
>>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


Jul 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Billy Jacobs | last post by:
I am using a datagrid to display some data. I need to create 2 header rows for this grid with columns of varying spans. In html it would be the following. <Table> <tr> <td colspan=8>Official...
3
by: sam | last post by:
Hello Group, Havent had luck posting it to microsoft.public.dotnet.framework.aspnet.datagridcontrol group. Excuse me for the cross posting. I have a datagrid which needs to be split into multiple...
8
by: DraguVaso | last post by:
Hi, I want to override the MyBase.OnPaint(ByVal pe As System.Windows.Forms.PaintEventArgs) of the DataGrid, to have some custom property's designed (other column headers etc). The problem is...
9
by: Morten | last post by:
Hi! I have a problem displaying some values in a datagrid. I have an array that consists of a number of objects. Each object has 2 properties: Name and a list of web addresses. (e.g: Name:...
5
by: Ben | last post by:
Is there any way to freeze the DataGrid headers so that the headers are always viewable while srolling down? Thanks in advance, Ben!
0
by: Hai Nguyen | last post by:
Below is my code, would anybody please figure out why it did not display any thing. The database did not anything in there yet, what it does is the header field. It just shows me the headers only,...
2
by: tshad | last post by:
I have a Datagrid that has no rows in it, but I want the title to show, and they aren't. Is there a way to make them visible even if the Datagrid is empty? Thanks, Tom
1
by: ElenaR | last post by:
I need to figure out how to name my column headers in a DataGrid. In VB6, I could write DataGrid1.Columns(0).Caption = "ID". What is the format for VB.NET? Thanks in Advance!
4
by: cooltech77 | last post by:
Hi, I am trying to build the following functionality in the datagrid. I have a lot of columns in the datagrid which are being populated from the database and the user needs to scroll...
3
by: Gidi | last post by:
Hi, I've a dataGrid, and When I click with the mouse on one of it's header the DataGrid_Click event is called. I don't have problem with the event, but strange things happen to the dataGrid...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.