468,306 Members | 1,171 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,306 developers. It's quick & easy.

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 4481
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Steve Klett | last post: by
2 posts views Thread by Mark | last post: by
1 post views Thread by Scott Schluer | last post: by
3 posts views Thread by Chris | last post: by
2 posts views Thread by Chris Fink | last post: by
2 posts views Thread by cindy | last post: by
7 posts views Thread by =?Utf-8?B?cGF0cmlja2RyZA==?= | last post: by
3 posts views Thread by Crazy Cat | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.