H
Hardy Wang
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?
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?