I'm trying to create a control based on RadComboBox that uses LoD and uses templates to display multicolumn data.
I can't figure out the proper place for the call to the DataBind() method.
I'm creating the control programmatically.
I've tried calling DataBind() on each RadComboBoxItem a couple of places in the Page_Load event and in the ItemsRequested event to no avail.
What should I be doing?
--
Stuart
I can't figure out the proper place for the call to the DataBind() method.
I'm creating the control programmatically.
namespace TestBed { | |
public partial class WebForm5 : System.Web.UI.Page { | |
DataSet _Data; | |
public DataSet Data { | |
get { | |
if(_Data == null || _Data.Tables.Count == 0) { | |
_Data = new DataSet(); | |
XmlDataDocument doc = new XmlDataDocument(); | |
doc.Load(System.Web.HttpContext.Current.Server.MapPath("App_Data/lstransact.xml")); | |
StringReader sr = new StringReader(doc.SelectSingleNode("//data").OuterXml); | |
XmlTextReader r = new XmlTextReader(sr); | |
_Data.ReadXml(r); | |
} | |
return _Data; | |
} | |
} | |
protected void Page_Load(object sender, EventArgs e) { | |
RadComboBox cb = CreateCombo(); | |
AjaxPanel.Controls.Add(cb); | |
} | |
RadComboBox CreateCombo() { | |
RadComboBox cb = new RadComboBox(); | |
cb.ID = "combo"; | |
cb.AllowCustomText = true; | |
cb.EnableLoadOnDemand = true; | |
cb.EnableVirtualScrolling = true; | |
cb.ShowMoreResultsBox = true; | |
cb.ShowToggleImage = true; | |
cb.HighlightTemplatedItems = true; | |
cb.MarkFirstMatch = false; | |
cb.Width = Unit.Pixel(250); | |
cb.Height = Unit.Pixel(200); | |
cb.HeaderTemplate = new HeaderTemplate(); | |
cb.ItemTemplate = new ItemTemplate(); | |
cb.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(cb_ItemsRequested); | |
return cb; | |
} | |
void cb_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) { | |
RadComboBox cb = (RadComboBox) o; | |
int offset = e.NumberOfItems; | |
DataRow[] rs = Data.Tables[0].Select(String.Format("trannum>={0}", e.Text == String.Empty ? "0" : e.Text)); | |
DataTable data = new DataTable(); | |
data = Data.Tables[0].Clone(); | |
foreach(DataRow r in rs) { | |
data.ImportRow(r); | |
} | |
int itemsPerRequest = 20; | |
int endOffset = offset + itemsPerRequest; | |
if(endOffset > data.Rows.Count) { | |
endOffset = data.Rows.Count; | |
} | |
if(endOffset == data.Rows.Count) { | |
e.EndOfItems = true; | |
} | |
else { | |
e.EndOfItems = false; | |
} | |
for(int i = offset;i < offset + itemsPerRequest;i++) { | |
RadComboBoxItem itm = new RadComboBoxItem(data.Rows[i]["trannum"].ToString()); | |
cb.Items.Add(itm); | |
} | |
if(data.Rows.Count > 0) { | |
e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), data.Rows.Count.ToString()); | |
} | |
else { | |
e.Message = "No matches"; | |
} | |
} | |
} | |
public class HeaderTemplate : ITemplate { | |
void ITemplate.InstantiateIn(Control container) { | |
Table t = new Table(); | |
TableRow r = new TableRow(); | |
TableCell c; | |
c = new TableCell(); | |
c.Width = Unit.Pixel(50); | |
c.Text = "Audit No"; | |
r.Cells.Add(c); | |
c = new TableCell(); | |
c.Width = Unit.Pixel(70); | |
c.Text = "Date"; | |
r.Cells.Add(c); | |
c = new TableCell(); | |
c.Width = Unit.Pixel(270); | |
c.Text = "Tenant name"; | |
r.Cells.Add(c); | |
t.Rows.Add(r); | |
container.Controls.Add(t); | |
} | |
} | |
public class ItemTemplate : ITemplate { | |
void ITemplate.InstantiateIn(Control container) { | |
Table t = new Table(); | |
TableRow r = new TableRow(); | |
TableCell c; | |
c = new TableCell(); | |
c.Width = Unit.Pixel(50); | |
c.Text = (string) DataBinder.Eval((container as RadComboBoxItem).DataItem, "trannum"); | |
r.Cells.Add(c); | |
c = new TableCell(); | |
c.Width = Unit.Pixel(70); | |
c.Text = (string) DataBinder.Eval((container as RadComboBoxItem).DataItem, "trandate"); | |
r.Cells.Add(c); | |
c = new TableCell(); | |
c.Width = Unit.Pixel(270); | |
c.Text = (string) DataBinder.Eval((container as RadComboBoxItem).DataItem, "toDbTenant-name"); | |
r.Cells.Add(c); | |
t.Rows.Add(r); | |
container.Controls.Add(t); | |
} | |
} | |
} |
I've tried calling DataBind() on each RadComboBoxItem a couple of places in the Page_Load event and in the ItemsRequested event to no avail.
What should I be doing?
--
Stuart