Posted by: Rajesh Kanaparti | March 25, 2008

Replacing Repeater with a ListView and getting access to DataItem, Simple…

I have seen questions online on how the DataBound event can be used  and how it is different comparable to repeater.Also some posts asking how to get access to dataitem. Its pretty simple.

Signature changes from

protected void uiRptOrderItems_DataBound(object sender, RepeaterItemEventArgs e)


protected void uiLVOrderItems_DataBound(object sender, ListViewItemEventArgs e)

and then checking for DataItem changes


if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)


if (e.Item.ItemType == ListViewItemType.DataItem)

And finally to get access to data item the code will be change from

OrderItem pet = e.Item.DataItem as OrderItem;


ListViewDataItem lvDataItem = (ListViewDataItem)e.Item;

                OrderItem item = lvDataItem .DataItem as OrderItem ;

Happy Coding!!


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: