using System; using System.Data; using System.Configuration; using System.Web; using System.Web.UI; using System.Text; public partial class Controls_VolumePricingTable : System.Web.UI.UserControl { private DataTable _DataSource; public DataTable DataSource { get { return _DataSource; } set { _DataSource = value; } } private string _RenderedTable; public void BindData() { if (_DataSource != null) { StringBuilder sb = new StringBuilder(); sb.Append(""); int LastQuantity = 0; for (int i = 0; i < _DataSource.Rows.Count; i++) { int ThisQuantity = (int)_DataSource.Rows[i]["Quantity"]; int NextQuantity = (i < _DataSource.Rows.Count-1 ? (int)_DataSource.Rows[i+1]["Quantity"]-1 : -9999); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); LastQuantity = ThisQuantity; } sb.Append("
"); sb.Append(String.Format("{0:c}", _DataSource.Rows[i]["Price"])); sb.Append(""); sb.Append(ThisQuantity.ToString()); if (NextQuantity == -9999) sb.Append(" or more"); else { sb.Append(" - "); sb.Append(NextQuantity.ToString()); sb.Append(" units"); } sb.Append("
"); _RenderedTable = sb.ToString(); } else _RenderedTable = null; } protected override void Render(HtmlTextWriter writer) { if (_RenderedTable != null) { base.Render(writer); writer.Write(_RenderedTable); } } }