473,499 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing the current DataItem in the ItemCommand event

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:

System.Diagnostics.Debug.WriteLine("IsNothing(e.It em.DataItem): " &
CStr(IsNothing(e.Item.DataItem)))
This statement ouput the value "True". Does anybody have any ideas as to
what might be a good way to get the column values that were used for the
current Item? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
May 28 '07 #1
1 7180
DataItem is available only in ItemDataBound event as it is the only time
where the control items connect to their datasource. If you need the
datasource field values in other places, you need to take a special care of
it. You may consider including the values in the item template and hiding
them with css style display:none. Then you can access them in postbacks.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:eG**************@TK2MSFTNGP04.phx.gbl...
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:

System.Diagnostics.Debug.WriteLine("IsNothing(e.It em.DataItem): " &
CStr(IsNothing(e.Item.DataItem)))
This statement ouput the value "True". Does anybody have any ideas as to
what might be a good way to get the column values that were used for the
current Item? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/


May 28 '07 #2

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

Similar topics

3
14695
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
4
1985
by: Steven | last post by:
Hi there, I am having a weird problem. I have a datagrid with both an ItemCommand and a SortCommand. It was working fine until a day ago. Now, whenever I click a column to fire the...
0
1271
by: Solomon Shaffer | last post by:
I am trying to add some link buttons to a datagrid template column at runtime and trying to wire these buttons up to the ItemCommand event (or any event when clicked!). The ItemCommand event works...
2
3347
by: Deepesh | last post by:
Good day, I have a specific case of the DataGrid in my solution which is causing the ItemCommand Event Not Firing. So I'm creating a "Skinnable" set of controls. I seperate the actual ASCX file...
4
4135
by: EvelynAnd Ethan | last post by:
Hi, ItemCommand event not firing from a dynamic user control ,WHERE A DATAGRID HAS BUTTON,when i click on the linkbutton first time the itemcommand event doesnt fire,second time event fires up ...
0
981
by: Nathan Sokalski | last post by:
I am using a DataList with Event Bubbling. When I bubble an event, the ItemCommand event is always called before the bubble event specified in the CommandName property. Is this ASP.NET's way of...
4
9044
by: John Kotuby | last post by:
Hi all, I am using a Repeater in conjunction with a SQLDatasource and SQL Server. One of the controls in the repeater is a HyperlLink as follows: <asp:HyperLink...
0
2047
by: Per W. | last post by:
Hi, in ItemDatabound i can use e.item.dataitem(x).Tostring to read a field from a datalist, but what to use to read from the datalist when a button in the selected row in the datalist is pushed and...
1
6734
by: Nathan Sokalski | last post by:
I have a custom Control that I have made that contains a DataList. In either the ItemCommand or SelectedIndexChanged event I need to retrieve a value from the DataItem of the SelectedItem. I have...
0
7131
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
7174
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,...
1
6894
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
7388
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...
0
5470
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,...
0
4600
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...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
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 ...
1
665
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.