By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,316 Members | 2,132 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,316 IT Pros & Developers. It's quick & easy.

DataList's ItemCreated event

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.