Based on the first answer, instead of building the table in the ItemDataBound function, you can pass your table data to Page_Load , set it to the ViewState variable, and then get it when binding:
private DataTable GetCachedDataTable(string strTable) { DataTable dtableCached = (DataTable)this.ViewState[strTableCache]; return dtableCached; } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { this.ViewState["TblTwo_Cache"] = null; DataTable tblOne = new DataTable(); DataTable tblTwo = new DataTable(); myFunctionReturningTwoTables(ref tblOne, ref tblTwo); // Bind the first one if (tblOne != null) { // This first line assumes an <asp:Panel ID=pnlMain runat=server> // tag is added in front of the Repeater1 tag in the ASPX markup, above, // and an </asp:Panel> tag is after the last </asp:Repeater> tag Repeater rptr = pnlMain.FindControl("Repeater1") as Repeater; rptr.ItemDataBound += new RepeaterItemEventHandler(rptrItemDataBound); rptr.DataSource = tblOne; rptr.DataBind(); } // Cache the 2nd (and others...) like this if (tblTwo != null) { this.ViewState["TblTwo_Cache"] = tblTwo; } } } protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rptr2 = e.Item.FindControl("Repeater2") as Repeater; if (rptr2 != null) { DataTable dt = new DataTable(); // Now, pull it out of cache dt = GetCachedDataTable("TblTwo_Cache"); if (dt != null) { rptr2.DataSource = dt; rptr2.DataBind(); } } } }
source share