473,569 Members | 2,879 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 2681
I created a function to handle the "grouping":

Private Sub GroupHeader(ByV al Item As
System.Web.UI.W ebControls.Data GridItem)

Dim tc As TableCell = New TableCell

tc.ColumnSpan = "4"

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

tc.ForeColor = System.Drawing. Color.White

tc.BackColor = System.Drawing. Color.Firebrick

Dim dgi As DataGridItem

If Item.ItemType = ListItemType.It em Then

dgi = New DataGridItem(2, 0, ListItemType.It em)

ElseIf Item.ItemType = ListItemType.Al ternatingItem Then

dgi = New DataGridItem(2, 0, ListItemType.Al ternatingItem)

End If

dgi.Cells.Add(t c)

DataGrid1.Contr ols(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*****@somewh ere.com> wrote in message
news:O4******** ******@TK2MSFTN GP12.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(ByV al Item As
System.Web.UI.W ebControls.Data GridItem)

Static LastItem As System.Web.UI.W ebControls.Data GridItem '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).T ext 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).T ext
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.It em Then
dgi = New DataGridItem(0, 0, ListItemType.It em)
ElseIf Item.ItemType = ListItemType.Al ternatingItem Then
dgi = New DataGridItem(0, 0, ListItemType.Al ternatingItem)
End If

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

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

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

End Sub

"Craig Buchanan" <so*****@somewh ere.com> wrote in message
news:O4******** ******@TK2MSFTN GP12.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
3653
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 the question simpler. First off, I've got three classes: Class MyItem Public Name As String Public ItemError As MyItemError End Class
8
3040
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 client-side coding needed for the user to click a "select" button (HTMLButton) in column 0 of the datagrid and have the table objects auto-fill with...
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
1956
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 DataGridItem(DataGrid1.Items.Count+1,DataGrid1.Items.Count+1,ListItemType.Item); di.Cells.Add(tc); di.Cells.Add(tc1);
0
1287
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 the datagrid. The second time i click on the header the top halve changes in the right order too. What i do wrong? btw if i remove...
4
3483
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 snippet from my .css file: *************************** body { margin:0; padding:0;
5
2082
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
2667
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 (ie. with empty cells). Unfortunatly I get no datagrid shown instead. Any idea how I can force the datagrid to show with an empty row? Best...
1
2580
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 cells - they are generated through the odswierz_frekfencje() function (listed below)-
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2118
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 we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.