473,466 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Accessing DataGridItem in ItemCreated Event.

Hello All,

When a datagrid in a web form is getting re populated from view state on
post back, it is firing the datagrid Item Created event but the
DataGridItem(e.Item.DataItem is null) in the event arguments has no values.
Is there any way to access and manipulate the row contents in this case ?

Thanks in advance for any insigts in to this.

-Souri
Nov 18 '05 #1
4 4350
Souri:
Your datasource isn't stored in the viewstate - which is why e.Item.DataItem
is null. Thankfully the viewstate only stores what it needs to recreate
the control as-is...otherwise it would grow to be too big.

Karl

"Souri Challa" <So*********@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
Hello All,

When a datagrid in a web form is getting re populated from view state on post back, it is firing the datagrid Item Created event but the
DataGridItem(e.Item.DataItem is null) in the event arguments has no values. Is there any way to access and manipulate the row contents in this case ?

Thanks in advance for any insigts in to this.

-Souri

Nov 18 '05 #2
Does this mean, it is not possible to inspect and change values of a
datagrid row
in Item created always ? When the datagrid is re-rendering its content from
viewstate
and firing the Item Created event, shouldn't there be some way to access the
values ?

I've a requirement to remove a button column based on a value in the row.
and replace the cell with text

I do some thing like..

if (e.item.cells[0].text == "Last Level"){
LinkButton lnkBtn = ((LinkButton)e.Item.Cells[2].Controls[0]);
e.Item.Cells[2].Text = lnkBtn.Text;
e.Item.Cells[2].Controls.Remove(lnkBtn);
}

( Disabling the button colum is not option here for me.)

I tried doing this in Item Data Bound, It works but it seems this change
is not saved to view state. Upon post back, I notice that Grid has empty
values
in cell[2].

Any Ideas ?

Thanks,
-Souri

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:eG*************@TK2MSFTNGP12.phx.gbl...
Souri:
Your datasource isn't stored in the viewstate - which is why e.Item.DataItem is null. Thankfully the viewstate only stores what it needs to recreate
the control as-is...otherwise it would grow to be too big.

Karl

"Souri Challa" <So*********@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
Hello All,

When a datagrid in a web form is getting re populated from view state

on
post back, it is firing the datagrid Item Created event but the
DataGridItem(e.Item.DataItem is null) in the event arguments has no

values.
Is there any way to access and manipulate the row contents in this case ?
Thanks in advance for any insigts in to this.

-Souri


Nov 18 '05 #3
ItemCreated isn't the place to do this. ItemDataBound is. Instead of
removing things, try to change their visibility. For example, try this in
your aspx file:

<asp:Literal ID="lit" Runat="server" />
<asp:LinkButton ID="lnk" Runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "FIELD")%>' />

And in your codebehind, do something like this:

Literal lit = (Literal)e.Item.FindControl("lit");
linkButton lnk = (LinkButton)e.Item.FindControl("lnk")
lit.Text = lnk.Text;
lnk.Visible = False;
lit.Visible = True;

Hope this helps,
Karl
"Souri Challa" <so*********@hotmail.com> wrote in message
news:mO0Yc.84014$mD.82428@attbi_s02...
Does this mean, it is not possible to inspect and change values of a
datagrid row
in Item created always ? When the datagrid is re-rendering its content from viewstate
and firing the Item Created event, shouldn't there be some way to access the values ?

I've a requirement to remove a button column based on a value in the row.
and replace the cell with text

I do some thing like..

if (e.item.cells[0].text == "Last Level"){
LinkButton lnkBtn = ((LinkButton)e.Item.Cells[2].Controls[0]);
e.Item.Cells[2].Text = lnkBtn.Text;
e.Item.Cells[2].Controls.Remove(lnkBtn);
}

( Disabling the button colum is not option here for me.)

I tried doing this in Item Data Bound, It works but it seems this change
is not saved to view state. Upon post back, I notice that Grid has empty
values
in cell[2].

Any Ideas ?

Thanks,
-Souri

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:eG*************@TK2MSFTNGP12.phx.gbl...
Souri:
Your datasource isn't stored in the viewstate - which is why e.Item.DataItem
is null. Thankfully the viewstate only stores what it needs to recreate
the control as-is...otherwise it would grow to be too big.

Karl

"Souri Challa" <So*********@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
Hello All,

When a datagrid in a web form is getting re populated from view
state on
post back, it is firing the datagrid Item Created event but the
DataGridItem(e.Item.DataItem is null) in the event arguments has no

values.
Is there any way to access and manipulate the row contents in this

case ?
Thanks in advance for any insigts in to this.

-Souri



Nov 18 '05 #4
Thanks a lot Karl. I'm still unclear why it is too late in the event cycle
to remove/add
controls in the Item Data Bound and what happens when DataGrid loads from
the view state.

Right now I'm using the datagrid button column in several pages with a
custom Grid class I wrote.
( which overrides the Item databound etc.)
This is the reason, why I'm a little reluctant to change the button column
to a template column
with two controls in it, in all pages.

-Regards,
Souri
"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:ex**************@tk2msftngp13.phx.gbl...
ItemCreated isn't the place to do this. ItemDataBound is. Instead of
removing things, try to change their visibility. For example, try this in
your aspx file:

<asp:Literal ID="lit" Runat="server" />
<asp:LinkButton ID="lnk" Runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "FIELD")%>' />

And in your codebehind, do something like this:

Literal lit = (Literal)e.Item.FindControl("lit");
linkButton lnk = (LinkButton)e.Item.FindControl("lnk")
lit.Text = lnk.Text;
lnk.Visible = False;
lit.Visible = True;

Hope this helps,
Karl
"Souri Challa" <so*********@hotmail.com> wrote in message
news:mO0Yc.84014$mD.82428@attbi_s02...
Does this mean, it is not possible to inspect and change values of a
datagrid row
in Item created always ? When the datagrid is re-rendering its content

from
viewstate
and firing the Item Created event, shouldn't there be some way to access

the
values ?

I've a requirement to remove a button column based on a value in the row.
and replace the cell with text

I do some thing like..

if (e.item.cells[0].text == "Last Level"){
LinkButton lnkBtn = ((LinkButton)e.Item.Cells[2].Controls[0]);
e.Item.Cells[2].Text = lnkBtn.Text;
e.Item.Cells[2].Controls.Remove(lnkBtn);
}

( Disabling the button colum is not option here for me.)

I tried doing this in Item Data Bound, It works but it seems this change is not saved to view state. Upon post back, I notice that Grid has empty
values
in cell[2].

Any Ideas ?

Thanks,
-Souri

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:eG*************@TK2MSFTNGP12.phx.gbl...
Souri:
Your datasource isn't stored in the viewstate - which is why

e.Item.DataItem
is null. Thankfully the viewstate only stores what it needs to

recreate the control as-is...otherwise it would grow to be too big.

Karl

"Souri Challa" <So*********@discussions.microsoft.com> wrote in message news:6B**********************************@microsof t.com...
> Hello All,
>
> When a datagrid in a web form is getting re populated from view state on
> post back, it is firing the datagrid Item Created event but the
> DataGridItem(e.Item.DataItem is null) in the event arguments has no
values.
> Is there any way to access and manipulate the row contents in this

case
?
>
> Thanks in advance for any insigts in to this.
>
> -Souri



Nov 18 '05 #5

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

Similar topics

3
by: Hardy Wang | last post by:
Hi all; I have a DataList with ItemCreated event like below: private void myList_ItemCreated(object sender , DataListItemEventArgs e) { DataRowView myRowView; DataRow myRow; if (e.Item.DataItem...
0
by: John Boldt | last post by:
I have a datalist control embedded within a repeater control. For some reason, the ItemCreated event fires twice for each data row. If I take the datalist out of the repeater control, it works...
0
by: tparks69 | last post by:
All I want to do is change the border of the first img control in my html to 0. The other images I want to have border=1. I have an event on my datalist that calls the following code: ...
3
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",...
0
by: rioka | last post by:
I'm going to display data with a repeater control, and each row can have a different layout depending on the value of a column: for example, if column A contains value "1" I want to display Column...
2
by: DC | last post by:
Hi, I am doing something like this in the ItemCreated event (ASP.Net 1.1): DataGridItem pagerRow = e.Item; TableCell pagerCell = pagerRow.Cells; Control addedControl = new Control();...
2
by: onerobe | last post by:
Hi everyone. I have this bizarre problem and i am hoping someone can point me in the right direction. I have a group of form selects, and when one is changed it dynamically changes the content...
2
by: archana | last post by:
Hi all, I am having one datagrid whose datasource i set as array. On itemcreated event i am having one counter which i have used to find out how many times item created event is fired. What...
3
by: =?Utf-8?B?U2F2dm91bGlkaXMgSW9yZGFuaXM=?= | last post by:
I have checked everything, events inside VS2008, or deleting the event and recreating it but nothing worked. I can't even make a breakpoint stop inside the event handler. Is it a bug of VS2008?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.