473,233 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,233 software developers and data experts.

DataList's ItemCreated event

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");
}

if ((e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem) && e.Item.DataItem != null) {
myRowView = (DataRowView) e.Item.DataItem;
myRow = myRowView.Row;
// do something with myRow["Column"]
} else if (e.Item.ItemType == ListItemType.EditItem && e.Item.DataItem !=
null) {
myRowView = (DataRowView) e.Item.DataItem;
myRow = myRowView.Row;
// do something with myRow["Column"]
}
}

I traced the event with Trace statement, and found that after page was
posted back, I got following values from trace.axd:
Item ---without data 0.090712 0.079591
AlternatingItem ---without data 0.091327 0.000614
Item ---without data 0.091959 0.000632
AlternatingItem ---without data 0.092603 0.000645
Which means e.Item.DataItem is always null.

Thus caused some section (to render the result within DataList for some
controls like Literal, Label and etc) won't get executed after posted back.
I enabled ViewState for all page, no single control is disabled to use
ViewState.

Anybody has some ideas?

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
Nov 17 '05 #1
3 4699
Forgot to mentio my ASPX page is like:
<asp:DataList id="myList" width="95%" CellSpacing="10" CellPadding="5"
border="0" RepeatDirection="horizontal" RepeatColumns="3" runat="server"
EnableViewState="True" DataKeyField="IDNumber">
<ItemStyle VerticalAlign="top" />
<ItemTemplate>
<b>Size</b> <asp:Literal id="lSize" EnableViewState="True" runat="server"
/> KB<br/>
<asp:LinkButton id="btnEdit" CommandName="Edit" Text="Edit"
CausesValidation="false" runat="server" />
</ItemTemplate>
<EditItemTemplate>
<b>Size</b> <asp:Literal id="lSize1" runat="server" /> KB<br/>
<table width=100% border=0>
<tr>
<td><asp:LinkButton CommandName="Update" id="btnUpdate" Text="Update"
CausesValidation="false" runat="server" /></td>
<td><asp:LinkButton CommandName="Cancel" id="btnCancel" Text="Calcen"
CausesValidation="false" runat="server" /></td>
<td><asp:LinkButton CommandName="Delete" id="btnDelete" Text="Delete"
CausesValidation="false" runat="server" /></td>
</tr>
</table>
</EditItemTemplate>
</asp:datalist>

The first time I run page, lSize in DataList will be populated with value,
but after posted back its value was lost...

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Hardy Wang" <ha********@marketrend.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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");
}

if ((e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem) && e.Item.DataItem != null) {
myRowView = (DataRowView) e.Item.DataItem;
myRow = myRowView.Row;
// do something with myRow["Column"]
} else if (e.Item.ItemType == ListItemType.EditItem && e.Item.DataItem !=
null) {
myRowView = (DataRowView) e.Item.DataItem;
myRow = myRowView.Row;
// do something with myRow["Column"]
}
}

I traced the event with Trace statement, and found that after page was
posted back, I got following values from trace.axd:
Item ---without data 0.090712 0.079591
AlternatingItem ---without data 0.091327 0.000614
Item ---without data 0.091959 0.000632
AlternatingItem ---without data 0.092603 0.000645
Which means e.Item.DataItem is always null.

Thus caused some section (to render the result within DataList for some
controls like Literal, Label and etc) won't get executed after posted back. I enabled ViewState for all page, no single control is disabled to use
ViewState.

Anybody has some ideas?

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy

Nov 17 '05 #2
The DataSource of the datalist is probably null on post back.

L.L.

"Hardy Wang" <ha********@marketrend.com> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
Forgot to mentio my ASPX page is like:
<asp:DataList id="myList" width="95%" CellSpacing="10" CellPadding="5"
border="0" RepeatDirection="horizontal" RepeatColumns="3" runat="server"
EnableViewState="True" DataKeyField="IDNumber">
<ItemStyle VerticalAlign="top" />
<ItemTemplate>
<b>Size</b> <asp:Literal id="lSize" EnableViewState="True" runat="server"
/> KB<br/>
<asp:LinkButton id="btnEdit" CommandName="Edit" Text="Edit"
CausesValidation="false" runat="server" />
</ItemTemplate>
<EditItemTemplate>
<b>Size</b> <asp:Literal id="lSize1" runat="server" /> KB<br/>
<table width=100% border=0>
<tr>
<td><asp:LinkButton CommandName="Update" id="btnUpdate" Text="Update"
CausesValidation="false" runat="server" /></td>
<td><asp:LinkButton CommandName="Cancel" id="btnCancel" Text="Calcen"
CausesValidation="false" runat="server" /></td>
<td><asp:LinkButton CommandName="Delete" id="btnDelete" Text="Delete"
CausesValidation="false" runat="server" /></td>
</tr>
</table>
</EditItemTemplate>
</asp:datalist>

The first time I run page, lSize in DataList will be populated with value,
but after posted back its value was lost...

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Hardy Wang" <ha********@marketrend.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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");
}

if ((e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem) && e.Item.DataItem != null) {
myRowView = (DataRowView) e.Item.DataItem;
myRow = myRowView.Row;
// do something with myRow["Column"]
} else if (e.Item.ItemType == ListItemType.EditItem && e.Item.DataItem != null) {
myRowView = (DataRowView) e.Item.DataItem;
myRow = myRowView.Row;
// do something with myRow["Column"]
}
}

I traced the event with Trace statement, and found that after page was
posted back, I got following values from trace.axd:
Item ---without data 0.090712 0.079591
AlternatingItem ---without data 0.091327 0.000614
Item ---without data 0.091959 0.000632
AlternatingItem ---without data 0.092603 0.000645
Which means e.Item.DataItem is always null.

Thus caused some section (to render the result within DataList for some
controls like Literal, Label and etc) won't get executed after posted

back.
I enabled ViewState for all page, no single control is disabled to use
ViewState.

Anybody has some ideas?

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy


Nov 17 '05 #3
Yes, I agree. But it also seems that ViewState did not include the value for
child control of DataList, if I don't use
DataBinder.Eval(Container.DataItem, "FieldName")%> to populate values.

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"L. L." <ll**@cyence.com> wrote in message
news:uc****************@TK2MSFTNGP09.phx.gbl...
The DataSource of the datalist is probably null on post back.

L.L.

"Hardy Wang" <ha********@marketrend.com> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
Forgot to mentio my ASPX page is like:
<asp:DataList id="myList" width="95%" CellSpacing="10" CellPadding="5"
border="0" RepeatDirection="horizontal" RepeatColumns="3" runat="server"
EnableViewState="True" DataKeyField="IDNumber">
<ItemStyle VerticalAlign="top" />
<ItemTemplate>
<b>Size</b> <asp:Literal id="lSize" EnableViewState="True" runat="server" /> KB<br/>
<asp:LinkButton id="btnEdit" CommandName="Edit" Text="Edit"
CausesValidation="false" runat="server" />
</ItemTemplate>
<EditItemTemplate>
<b>Size</b> <asp:Literal id="lSize1" runat="server" /> KB<br/>
<table width=100% border=0>
<tr>
<td><asp:LinkButton CommandName="Update" id="btnUpdate" Text="Update"
CausesValidation="false" runat="server" /></td>
<td><asp:LinkButton CommandName="Cancel" id="btnCancel" Text="Calcen"
CausesValidation="false" runat="server" /></td>
<td><asp:LinkButton CommandName="Delete" id="btnDelete" Text="Delete"
CausesValidation="false" runat="server" /></td>
</tr>
</table>
</EditItemTemplate>
</asp:datalist>

The first time I run page, lSize in DataList will be populated with value, but after posted back its value was lost...

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Hardy Wang" <ha********@marketrend.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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");
}

if ((e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem) && e.Item.DataItem != null) {
myRowView = (DataRowView) e.Item.DataItem;
myRow = myRowView.Row;
// do something with myRow["Column"]
} else if (e.Item.ItemType == ListItemType.EditItem &&
e.Item.DataItem
!= null) {
myRowView = (DataRowView) e.Item.DataItem;
myRow = myRowView.Row;
// do something with myRow["Column"]
}
}

I traced the event with Trace statement, and found that after page was
posted back, I got following values from trace.axd:
Item ---without data 0.090712 0.079591
AlternatingItem ---without data 0.091327 0.000614
Item ---without data 0.091959 0.000632
AlternatingItem ---without data 0.092603 0.000645
Which means e.Item.DataItem is always null.

Thus caused some section (to render the result within DataList for

some controls like Literal, Label and etc) won't get executed after posted

back.
I enabled ViewState for all page, no single control is disabled to use
ViewState.

Anybody has some ideas?

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy



Nov 17 '05 #4

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

Similar topics

7
by: Steve Klett | last post by:
I would like to have DHTML on my DataList so that when I hover over a cell, it will change colors. I can't find a way to get onMouseOver into the generated <td> from a DataList. There must be ...
2
by: Mark | last post by:
I have a datalist (see code below). Assume that the datalist is populated with 10 records of data. How do I programatically grab all the data in ALL the columns of the selected record? I've been...
1
by: Scott Schluer | last post by:
Hello, I've got myself a small problem and I'm hoping someone can help. I have a DataList called dlProducts (displays products from a database). Within the <ItemTemplate> container of the...
3
by: Chris | last post by:
Hi Folks, well I have this "small" problem with the footertemplate in a datalist. I added a button and a textbox to update the db with the given String of the Textbox. I already searched for...
2
by: Chris Fink | last post by:
This should be relatively simple but I am unable to find an asp:button tag in a datalist footer. I have tried it numerous ways including the FindControl method from the many events that the...
2
by: cindy | last post by:
When my datalist loads I am trying to make the checked value in a radio button group reflect which value is stored in the data and then fire and event when the CheckChanged event fires. private...
0
by: fig000 | last post by:
Hi, I have a datalist with bound data from a database. If I wanted to access one of the fields I would normally use the itemdatabound event to access that field on each row. However in this...
7
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi all! I have a gridview inside a datagrid (nested) for which (gridview) the rowcommand is not raised in order to delete a row from the grid! I also tried OnRowCommand="method", didn't work...
3
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.