473,830 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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********@hotm ail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
5 1539
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********@hot mail.com> wrote in message
news:uQ******** ******@tk2msftn gp13.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********@hotm ail.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********@hotm ail.com
http://www.nathansokalski.com/

"Adam Knight" <ad**@pertrain. com.au> wrote in message
news:%2******** ********@TK2MSF TNGP15.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_Item DataBound(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data ListItemEventAr gs) Handles
datRatings.Item DataBound

If CInt(CType(e.It em.DataItem, DataRowView)("t imesrated")) > 1 Then

If e.Item.ItemType = ListItemType.It em Then
CType(e.Item.Fi ndControl("lblT imesRated1"), Label).Text &= "s"

If e.Item.ItemType = ListItemType.Al ternatingItem Then
CType(e.Item.Fi ndControl("lblT imesRated2"), 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.NullRefe renceException: Object reference not set
to an instance of an object.

Source Error:

Line 140:
Line 141: Private Sub datRatings_Item DataBound(ByVal sender As
Object, ByVal e As System.Web.UI.W ebControls.Data ListItemEventAr gs) Handles
datRatings.Item DataBound
Line 142: If CInt(CType(e.It em.DataItem,
DataRowView)("t imesrated")) > 1 Then
Line 143: If e.Item.ItemType = ListItemType.It em Then
CType(e.Item.Fi ndControl("lblT imesRated1"), Label).Text &= "s"
Line 144: If e.Item.ItemType = ListItemType.Al ternatingItem
Then CType(e.Item.Fi ndControl("lblT imesRated2"), Label).Text &= "s"

Source File: C:\Inetpub\wwwr oot\poetry\poem ratings.aspx.vb Line: 142
Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Adam Knight" <ad**@pertrain. com.au> wrote in message
news:%2******** ********@TK2MSF TNGP15.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.It em Or e.Item.ItemType =
ListItemType.Al ternatingItem
' Process
End If

Otherwise, you might get Null Object reference error.

HTH

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

Private Sub datRatings_Item DataBound(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data ListItemEventAr gs) Handles
datRatings.Item DataBound

If CInt(CType(e.It em.DataItem, DataRowView)("t imesrated")) > 1 Then

If e.Item.ItemType = ListItemType.It em Then
CType(e.Item.Fi ndControl("lblT imesRated1"), Label).Text &= "s"

If e.Item.ItemType = ListItemType.Al ternatingItem Then
CType(e.Item.Fi ndControl("lblT imesRated2"), 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.NullRefe renceException: Object reference not set
to an instance of an object.

Source Error:

Line 140:
Line 141: Private Sub datRatings_Item DataBound(ByVal sender As
Object, ByVal e As System.Web.UI.W ebControls.Data ListItemEventAr gs)
Handles datRatings.Item DataBound
Line 142: If CInt(CType(e.It em.DataItem,
DataRowView)("t imesrated")) > 1 Then
Line 143: If e.Item.ItemType = ListItemType.It em Then
CType(e.Item.Fi ndControl("lblT imesRated1"), Label).Text &= "s"
Line 144: If e.Item.ItemType = ListItemType.Al ternatingItem
Then CType(e.Item.Fi ndControl("lblT imesRated2"), Label).Text &= "s"

Source File: C:\Inetpub\wwwr oot\poetry\poem ratings.aspx.vb Line: 142
Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Adam Knight" <ad**@pertrain. com.au> wrote in message
news:%2******** ********@TK2MSF TNGP15.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
15202
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 I can pass the key value onto another page, which is showing me more details for the selected row. So in the double click event of the datagrid I have this code: DataRow CurrentRow = dsJobList.Tables.Rows;
3
14731
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
2633
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 columns. Three are databound to a dataset and one is a template column. I need to be able to access each item in the template column (getting access to the hyperlink) then adding an attribute to call some client side code. Does anyone know...
10
4959
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 the column order of the datatable). I also allow the user to click on a column header to sort the datagrid by that column. I need to identify the row and column in the datatable when the user clicks on a cell in the datagrid. Using the...
5
2011
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 this? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
5
3746
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 using code such as the following: If e.Item.ItemIndex=(numberofitems-1) Then mycontrol.Enabled=False but I cannot find a property that contains the total number of items before
2
15375
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 this.pitagoralavoriDataSet.Addetti.Rows) { if (Convert.ToString(row)== sNomeU){ idutente = Convert.ToInt32(row); }
5
39692
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 I would like to give those related DataGridViewRows a different BackColor. Thanks for hints and help! Rainer
1
7200
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 current DataItem is the following: CStr(CType(e.Item.DataItem, DataRowView)("id")) However, after some experimenting, I found out that e.Item.DataItem is Nothing in the ItemCommand event by using the following statement:
0
9791
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10771
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10525
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10202
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5617
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4411
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
3
3076
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.