Last post Jun 03, 2010 06:45 AM by Saravanan M
May 30, 2010 12:18 PM|mikeroberts|LINK
I have two web forms each having a Repeater which is being populated with the same data, although data is displayed in a different way.
In order not to replicate the code on both web forms, I created what I am calling a Helper class so as from BOTH web forms I can pass the datatable with the the data and the Repeater control.
My concern before I keep on using this approach for the whole website is that the methods in the Helper class are both static and the ItemDataBound one is the one which is making me worry the most.
Will I have bottleneck or performance problems by adopting this approach?
The code in the Helper class is below:
public static void ShowMonths(Repeater repMonths, DataTable dtMonths)
repMonths.ItemDataBound += new RepeaterItemEventHandler(repMonths_ItemDataBound);
repMonths.DataSource = dtMonths;
private static void repMonths_ItemDataBound(object sender, RepeaterItemEventArgs e)
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
((Literal)e.Item.FindControl("litMonthName")).Text = ((DataRowView)e.Item.DataItem)["monthName"]).ToString());
May 30, 2010 12:47 PM|PeteNet|LINK
If the data is the same for both pages (repeaters in those pages) and doesn't change often you could persist the datasource (datatable etc) in the cache (see nine options to persist user state)
If you don't want to replicate code you could use a usercontrol housing the Repeater and then use that usercontrol on multiple pages.
Note that the ItemDataBound is going to be raised any and every time the data bound to the repeater changes or is changed.
May 30, 2010 12:55 PM|mikeroberts|LINK
The data is already in the cache but mine is not a problem of data but of display.
Also, I cannot host the Repeater in a user control as although the two Repeaters have the same web controls, the ItemTemplate is different, different CSS classes and so on.
May 30, 2010 01:50 PM|PeteNet|LINK
If you bind the Literal declaratively, you probably wouldn't need the ItemDataBound (if that helps in taking that one off, and wouldn't need the dynamic wire-up for the ItemDataBound)
<asp:Literal ID="Literal1" runat="server" Text='<%# Eval("ColumnName") %>' />
all that would remain is the datasource to be bound which could be kept in the respective page(s).
I guess I don't see the benefit with this approach.
Jun 03, 2010 06:45 AM|Saravanan M|LINK
Alternatively, use singleton pattern instead of static methods.