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)

to

protected void uiLVOrderItems_DataBound(object sender, ListViewItemEventArgs e)

and then checking for DataItem changes

from

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

to 

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;

to  

ListViewDataItem lvDataItem = (ListViewDataItem)e.Item;

                OrderItem item = lvDataItem .DataItem as OrderItem ;

Happy Coding!!

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

w

Connecting to %s

Categories

%d bloggers like this: