473,508 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datagrid cells addrow?

Is there a way to add a row to a datagrid during the ItemDataBound event? I
would like to add a 'header' row before the start of a group of rows.

Thanks,

Craig Buchanan
Nov 18 '05 #1
2 2672
I created a function to handle the "grouping":

Private Sub GroupHeader(ByVal Item As
System.Web.UI.WebControls.DataGridItem)

Dim tc As TableCell = New TableCell

tc.ColumnSpan = "4"

tc.Text = Item.Cells(3).Text & "[" & Item.ItemIndex & "]"

tc.ForeColor = System.Drawing.Color.White

tc.BackColor = System.Drawing.Color.Firebrick

Dim dgi As DataGridItem

If Item.ItemType = ListItemType.Item Then

dgi = New DataGridItem(2, 0, ListItemType.Item)

ElseIf Item.ItemType = ListItemType.AlternatingItem Then

dgi = New DataGridItem(2, 0, ListItemType.AlternatingItem)

End If

dgi.Cells.Add(tc)

DataGrid1.Controls(0).Controls.AddAt(2, dgi)

End Sub

I call this function in the ItemDataBound event if the itemtype is an
alternatingitem or an Item

Unfortunately, the new rows don't show up where I'd expect.

Can anyone explain what the first two arguments of the DataGridItem
constructor really mean? Also, if I add a row, does that change the
ItemIndex of the bound Item?

Thanks,

Craig

"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:O4**************@TK2MSFTNGP12.phx.gbl...
Is there a way to add a row to a datagrid during the ItemDataBound event? I would like to add a 'header' row before the start of a group of rows.

Thanks,

Craig Buchanan

Nov 18 '05 #2
Solved it:

Private Sub GroupHeader(ByVal Item As
System.Web.UI.WebControls.DataGridItem)

Static LastItem As System.Web.UI.WebControls.DataGridItem 'track the
last item
Static Groups As Integer 'track number of group rows added to
datagrid

If (Not LastItem Is Nothing) Then
'compare text value in prior row to text in current row (change cell as
appropriate)
'if text value hasn't changed, still in same group, exit
If LastItem.Cells(3).Text = Item.Cells(3).Text Then Exit Sub
End If

'increment group counter
Groups += 1

'create a new cell with appropriate properties
Dim tc As TableCell = New TableCell
tc.ColumnSpan = "4" 'span the table
tc.Text = Item.Cells(3).Text
tc.ForeColor = System.Drawing.Color.White
tc.BackColor = System.Drawing.Color.Firebrick

'create a new row. probably doesn't matter with listittemtype
Dim dgi As DataGridItem
If Item.ItemType = ListItemType.Item Then
dgi = New DataGridItem(0, 0, ListItemType.Item)
ElseIf Item.ItemType = ListItemType.AlternatingItem Then
dgi = New DataGridItem(0, 0, ListItemType.AlternatingItem)
End If

'add cell to new row
dgi.Cells.Add(tc)

'add row to datagrid; use group counter to correctly position row (each row
that is added
increments the ItemIndex)
DataGrid1.Controls(0).Controls.AddAt(Item.ItemInde x + Groups, dgi)

'store this item to be use in next pass
LastItem = Item

End Sub

"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:O4**************@TK2MSFTNGP12.phx.gbl...
Is there a way to add a row to a datagrid during the ItemDataBound event? I would like to add a 'header' row before the start of a group of rows.

Thanks,

Craig Buchanan

Nov 18 '05 #3

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

Similar topics

1
3646
by: TB | last post by:
Relatively new to .NET so please bear with me... I'm making an ASP.NET web application and am using VB to code. I'll try to set the stage here... The class and property names are generic to make...
8
3034
by: Sue | last post by:
I have a datagrid populated with 6 visible read-only labels and several hidden fields. Below the datagrid, I have a table with various textboxes, dropdowns, etc. I've managed to decypher the...
0
312
by: Craig Buchanan | last post by:
Is there a way to add a row to a datagrid during the ItemDataBound event? I would like to add a 'header' row before the start of a group of rows. Thanks, Craig Buchanan
2
1949
by: Praveen Balanagendra via .NET 247 | last post by:
here is the source code private void AddRow() { TableCell tc = new TableCell(); tc.Controls.Add(new LiteralControl("NewRow")); DataGridItem di = new...
0
1285
by: Danny | last post by:
I am trying to sort my second datagrid. And it works but only after i click 2 times on the column header. The first time i click on the header the data in the right order will add to the rows in...
4
3477
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
5
2078
by: John M | last post by:
Hello, In Visual Studio .NET 2003, How can I change the columns' width (at design or runtime) of datagrid ? Thanks :)
2
2662
by: carballosa | last post by:
Hi guys, I need to use a one row datagrid in my asp.net 1.1 application. The data source will contain 1 or 0 entries. When no rows of data are present I want to show an empty row in the datagrid...
1
2576
by: sp | last post by:
Hello I have a problem with the refresh performance in datagrid – when datagrid is being shown it is so slow that I can see one by one cells is drawn -datagrid contains about 35x40 of...
0
7226
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
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5631
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1561
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.