datagrid.. Is 2 rows per record possible?

R

rooster575

I would like my datagrid to have the following format:

ID - Name - Phone
Title - Birthday - email

Is this possible for the header and result items?

Thanks.
 
K

Ken Cox [Microsoft MVP]

Hello, ah is rooster your real name?

Here's some code that should give you some idea how to approach this. You
need to create a new header, and determine which cells should have text. You
also have to erase text from the existing header. After all is done, you add
the new header to the datagrid. It is late, so I can't do more but ask again
if you need help with hout it works.

Ken
Microsoft MVP [ASP.NET]
Ken


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 DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New 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


<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>
 
R

rooster575

Thanks Ken.. I'll give it a try.


Ken Cox said:
Hello, ah is rooster your real name?

Here's some code that should give you some idea how to approach this. You
need to create a new header, and determine which cells should have text. You
also have to erase text from the existing header. After all is done, you add
the new header to the datagrid. It is late, so I can't do more but ask again
if you need help with hout it works.

Ken
Microsoft MVP [ASP.NET]
Ken


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 DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New 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


<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>

rooster575 said:
I would like my datagrid to have the following format:

ID - Name - Phone
Title - Birthday - email

Is this possible for the header and result items?

Thanks.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top