473,662 Members | 2,724 Online
Bytes | Software Development & Data Engineering Community
+ 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 4372
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*********@di scussions.micro soft.com> wrote in message
news:6B******** *************** ***********@mic rosoft.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.Remov e(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******** *****@TK2MSFTNG P12.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*********@di scussions.micro soft.com> wrote in message
news:6B******** *************** ***********@mic rosoft.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:LinkButt on ID="lnk" Runat="server" Text='<%#
DataBinder.Eval (Container.Data Item, "FIELD")%>' />

And in your codebehind, do something like this:

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

Hope this helps,
Karl
"Souri Challa" <so*********@ho tmail.com> wrote in message
news:mO0Yc.8401 4$mD.82428@attb i_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.Remov e(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******** *****@TK2MSFTNG P12.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*********@di scussions.micro soft.com> wrote in message
news:6B******** *************** ***********@mic rosoft.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******** ******@tk2msftn gp13.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:LinkButt on ID="lnk" Runat="server" Text='<%#
DataBinder.Eval (Container.Data Item, "FIELD")%>' />

And in your codebehind, do something like this:

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

Hope this helps,
Karl
"Souri Challa" <so*********@ho tmail.com> wrote in message
news:mO0Yc.8401 4$mD.82428@attb i_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.Remov e(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******** *****@TK2MSFTNG P12.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*********@di scussions.micro soft.com> wrote in message news:6B******** *************** ***********@mic rosoft.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
4725
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 != null) { Trace.Write(e.Item.ItemType.ToString(), "---with data"); } else { Trace.Write(e.Item.ItemType.ToString(), "---without data"); }
0
1408
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 fine. What's going on? --- Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
0
815
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: ************** public void main_ItemCreated(Object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item) { HtmlImage imgPatron = new HtmlImage(); imgPatron = (HtmlImage)e.Item.FindControl(Request.Form);
3
3317
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", "Value" Depending on the "Locked" field in the source... I want the "Value" cell to be readonly or not for each row
0
1322
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 B; but if column A contains value "2", I'm going to display column C and D. (real situation is a bit more complicated, of course). I've been searching around in the past few days trying to get experiences from others having similar problems,...
2
6750
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(); addedControl.ID = "addedControl"; pagerCell.Controls.Add(addedControl);
2
2134
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 of the next. fairly bog standard. no problems there. I also have an image map. You click on part of the image and it calls a javascript function which then sets the select index and triggers the onchange() event. The href: ...
2
2280
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 i observerd is itemcreated event is fired twice than total items present in array.
3
1806
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?
0
8345
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,...
1
8547
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
8633
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
7368
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
5655
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
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
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
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1754
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.