473,326 Members | 2,111 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,326 software developers and data experts.

Accessing the current DataRow of the DataSource from ItemDataBound

I want to access the DataRow used in DataBinding from the ItemDataBound
event. In my case, the reason for doing this is to determine whether I need
to make a word singular or plural. How can I do this? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
5 1522
Use the DataGridItems DataItem method.
It Returns a reference to the source data row as a DataRowView object.

Hope it helps.
Adam
Nov 19 '05 #2
Hi,

http://www.windowsformsdatagridhelp....5-b1ec09f63071

Ken
----------
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
I want to access the DataRow used in DataBinding from the ItemDataBound
event. In my case, the reason for doing this is to determine whether I need
to make a word singular or plural. How can I do this? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #3
This seems to work except for one thing. I get the error "Option Strict On
disallows late binding." I can obviously turn Option Strict Off, but if
possible I would like to avoid doing this. Is this possible? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Adam Knight" <ad**@pertrain.com.au> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Use the DataGridItems DataItem method.
It Returns a reference to the source data row as a DataRowView object.

Hope it helps.
Adam

Nov 19 '05 #4
Could you give me an example? I am using the following code:

Private Sub datRatings_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
datRatings.ItemDataBound

If CInt(CType(e.Item.DataItem, DataRowView)("timesrated")) > 1 Then

If e.Item.ItemType = ListItemType.Item Then
CType(e.Item.FindControl("lblTimesRated1"), Label).Text &= "s"

If e.Item.ItemType = ListItemType.AlternatingItem Then
CType(e.Item.FindControl("lblTimesRated2"), Label).Text &= "s"

End If

End Sub
And am recieving the following error:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 140:
Line 141: Private Sub datRatings_ItemDataBound(ByVal sender As
Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles
datRatings.ItemDataBound
Line 142: If CInt(CType(e.Item.DataItem,
DataRowView)("timesrated")) > 1 Then
Line 143: If e.Item.ItemType = ListItemType.Item Then
CType(e.Item.FindControl("lblTimesRated1"), Label).Text &= "s"
Line 144: If e.Item.ItemType = ListItemType.AlternatingItem
Then CType(e.Item.FindControl("lblTimesRated2"), Label).Text &= "s"

Source File: C:\Inetpub\wwwroot\poetry\poemratings.aspx.vb Line: 142
Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Adam Knight" <ad**@pertrain.com.au> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Use the DataGridItems DataItem method.
It Returns a reference to the source data row as a DataRowView object.

Hope it helps.
Adam

Nov 19 '05 #5
Limiting your logic in
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem
' Process
End If

Otherwise, you might get Null Object reference error.

HTH

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:OE****************@TK2MSFTNGP14.phx.gbl...
Could you give me an example? I am using the following code:

Private Sub datRatings_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
datRatings.ItemDataBound

If CInt(CType(e.Item.DataItem, DataRowView)("timesrated")) > 1 Then

If e.Item.ItemType = ListItemType.Item Then
CType(e.Item.FindControl("lblTimesRated1"), Label).Text &= "s"

If e.Item.ItemType = ListItemType.AlternatingItem Then
CType(e.Item.FindControl("lblTimesRated2"), Label).Text &= "s"

End If

End Sub
And am recieving the following error:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 140:
Line 141: Private Sub datRatings_ItemDataBound(ByVal sender As
Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
Handles datRatings.ItemDataBound
Line 142: If CInt(CType(e.Item.DataItem,
DataRowView)("timesrated")) > 1 Then
Line 143: If e.Item.ItemType = ListItemType.Item Then
CType(e.Item.FindControl("lblTimesRated1"), Label).Text &= "s"
Line 144: If e.Item.ItemType = ListItemType.AlternatingItem
Then CType(e.Item.FindControl("lblTimesRated2"), Label).Text &= "s"

Source File: C:\Inetpub\wwwroot\poetry\poemratings.aspx.vb Line: 142
Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Adam Knight" <ad**@pertrain.com.au> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Use the DataGridItems DataItem method.
It Returns a reference to the source data row as a DataRowView object.

Hope it helps.
Adam


Nov 19 '05 #6

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

Similar topics

4
by: Steve | last post by:
Visual Studio 2003 .Net / C# I have a datagrid, which is bound to a dataset at runtime when my page loads. When the user double clicks a row, I need to find out which row they have selected so...
3
by: DonRex | last post by:
Hello all! I couldn't find a web application-newsgroup for ASP.NET, so I'm sorry if this is the wrong forum! Synopsis: In my webform I have 3 nested repeaters: rpWeeks ----- rpTime
2
by: damonf | last post by:
I'm currently trying to add an ASP hyperlink to a template column in a datagrid. The normal hyperlink column doesn't give me the ability to add attributes to the item. In my grid there are four...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
5
by: Nathan Sokalski | last post by:
I want to access the DataRow used in DataBinding from the ItemDataBound event. In my case, the reason for doing this is to determine whether I need to make a word singular or plural. How can I do...
5
by: Nathan Sokalski | last post by:
I have a control that I want displayed in all items except the last one. I figured the best way to do this was to determine whether the current item was the last from within the ItemDataBound event...
2
by: paolol | last post by:
Hi, I wont to get the current row values from a dataset, any one know how to reach those data ?? At the moment I use a work around, but it's not good .. foreach (DataRow row in...
5
by: Rainer Queck | last post by:
Hello NG, what would be the best way to locate a DataRrow in a DataGridView? I have by DataTable.Select a bunch of DataRows from a DataTable (which is the data source to the DataGridView). Now...
1
by: Nathan Sokalski | last post by:
I need to access one of the columns from the current DataItem in the ItemCommand event, which I call using EventBubbling with a DataList and Button control. The code I tried to use to access the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.