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

Home Posts Topics Members FAQ

DataGrid - ItemDataBound

Hey Guys,

I need to manipulate the data that is binding to a datagrid BEFORE its appearance to the user. Because I need to format it inside an If Clause.

I was putting my code in the ItemDataBound Event:

Dim shoCont As Integer

Try
Long.Parse(e.Item.Cells(1).Text)
Catch ex As Exception
Exit Sub
End Try

If e.Item.Cells(1).Text <> e.Item.Cells(2).Text Then
For shoCont = 0 To e.Item.Cells.Count
e.Item.Cells(2).ForeColor = System.Drawing.Color.Red
lngTotalDifi += Long.Parse(e.Item.Cells(2).Text) - Long.Parse(e.Item.Cells(1).Text)
Next
End If
BUT IT ISN'T WORKING????
WHAT IS WRONG???

THANK'S
Nov 18 '05 #1
1 4916
Hi André,

I used your code in my own page and it worked fine with a minor addition.
Here's what I used in case you need to compare:

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.AlternatingItem _
Or e.Item.ItemType = ListItemType.Item Then
Dim shoCont As Integer
Dim lngTotalDifi As Long
Dim strText As String
Try
strText = e.Item.Cells.Item(1).Text()
Long.Parse(e.Item.Cells(1).Text)
Catch ex As Exception
Exit Sub
End Try

If e.Item.Cells(1).Text <> e.Item.Cells(2).Text Then
For shoCont = 0 To e.Item.Cells.Count
e.Item.Cells(2).ForeColor = System.Drawing.Color.Red
lngTotalDifi += Long.Parse(e.Item.Cells(2).Text) _
- Long.Parse(e.Item.Cells(1).Text)
Next
End If
End If
End Sub

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("StringValue2", GetType(String)))
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("IntegerValue2", 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) = "Item2 " + i.ToString()
dr(1) = i
dr(2) = i * i
dr(3) = "Item " + i.ToString()
dr(4) = 1.23 * (i + 1)
dr(5) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource

Ken
Microsoft MVP [ASP.NET]
"André Almeida Maldonado" <de***@bol.com.br> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl...
Hey Guys,

I need to manipulate the data that is binding to a datagrid BEFORE its
appearance to the user. Because I need to format it inside an If Clause.

I was putting my code in the ItemDataBound Event:

Dim shoCont As Integer

Try
Long.Parse(e.Item.Cells(1).Text)
Catch ex As Exception
Exit Sub
End Try

If e.Item.Cells(1).Text <> e.Item.Cells(2).Text Then
For shoCont = 0 To e.Item.Cells.Count
e.Item.Cells(2).ForeColor = System.Drawing.Color.Red
lngTotalDifi += Long.Parse(e.Item.Cells(2).Text) -
Long.Parse(e.Item.Cells(1).Text)
Next
End If
BUT IT ISN'T WORKING????
WHAT IS WRONG???

THANK'S

Nov 18 '05 #2

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

Similar topics

8
7886
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
0
1542
by: Bob Rosen | last post by:
The description given in "Customizing Items Dynamically in the DataList or DataGrid Web Server Control" (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vbCode/...
2
16975
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
3
4889
by: vinayak | last post by:
Hi I am displaying data in Datagrid in ASP.NET with Edit/Update functionality for each row. On the same page I have 2 Button controls which submits the request to server. These button controls...
7
1983
by: Scott Schluer | last post by:
Hi All, I have a functioning datagrid on "Page 1" that displays order information for a single order (this is for an e-commerce site). It's actually a combination of a couple datagrids to...
2
2376
by: andla | last post by:
Hi, How does events fire in a datagrid. I know about the problem if turning the viewstate off the events wil not fire properly even if I rebind the control in every postback. S then I started...
2
3170
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to...
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...
3
3304
by: Lars Netzel | last post by:
(applies to Windows Form .NET 2003) I'm filling a datagrid from a Datatable and applying a DataGridStyle. The Source Fields are "Name", "Value", "Locked" and the Style's Columns are "Name",...
1
2545
by: needin4mation | last post by:
Hi, I have a datalist. In this datalist I have a datagrid. The datalist is the master. The datagrid is the detail. It works fine. I populate the datagrid inside of the datalist using the...
0
7225
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
7123
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
7042
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
5627
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,...
1
5052
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...
0
3193
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
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
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...

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.