473,941 Members | 14,220 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 21 '05 #1
5 2016
Use the DataGridItems DataItem method.
It Returns a reference to the source data row as a DataRowView object.

Hope it helps.
Adam
Nov 21 '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 21 '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 21 '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 21 '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 21 '05 #6

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

Similar topics

4
15213
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
14736
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
2638
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...
5
1545
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/
10
4971
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
3750
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
15384
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
39721
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
2
4843
by: =?Utf-8?B?TWFyYw==?= | last post by:
In Visual Studio 2005, I am developing a Windows Mobile application, using Mobile SQL 2005. I need Data from a Database to be shown in a DataGrid, this works. But now I want to be able to get the Data of the selected DataRow, for instance, I want to display the value of the "Klant" column of the selected Row using: DataRow currentRow = table.Rows; MessageBox.Show(currentRow.ToString());
1
7208
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
10134
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
9964
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
11112
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9858
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7389
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6079
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
6298
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4908
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
2
4449
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.