please help problem in creating template at run time.
-
Hi all, I am using asp.net and C# Visual studio 2005. Let me explain the scenario. I have stored procedure which return very no of column based on condition. Becoz I have to show columnwise record I used datalist. And becoz of query return different no of column based on condtion I created template class for design and itembinding at run time . I manage to create template column() but confuse over how to bind data. As no of column differ at runtime. Code I used I am attaching it below . if you have better approach please tell me Please guide me . 1 public class MyTemplate:ITemplate 2 { 3 ListItemType templateType; 4 String para1, para2, para3, para4, para5; 5 6 7 public MyTemplate(System.Web.UI.WebControls.ListItemType type,string parameter1) 8 { 9 templateType = type; 10 para1 = parameter1; 11 } 12 13 // 14 public void InstantiateIn(System.Web.UI.Control container ) 15 { 16 PlaceHolder ph = new PlaceHolder(); 17 ImageMap imp = new ImageMap(); 18 //declaration 19 imp.ID = "img1"; 20 21 switch (templateType) 22 { 23 case ListItemType.Header: 24 // ph.Controls.Add(new LiteralControl(" ")); 25 ph.Controls.Add(new LiteralControl("<table border=\"1\">" )); 26 break; 27 case ListItemType.Item: 28 29 ph.Controls.Add(new LiteralControl("<tr align = left>")); 30 ph.Controls.Add(imp); 31 // some code 32 //optional parameter 33 if (!((para1 == "categoryid") || (para1 == "customerid") || (para1 == "retailprice") || (para1 == "subcategory"))) 34 { 35 ph.Controls.Add(item5); 36 ph.Controls.Add(new LiteralControl("<br />")); 37 38 } 39 40 ph.Controls.Add(new LiteralControl("</td>")); 41 ph.DataBinding += new EventHandler(Item_DataBinding); 42 break; 43 44 case ListItemType.Footer: 45 ph.Controls.Add(new LiteralControl("</table>")); 46 47 break; 48 } 49 container.Controls.Add(ph); 50 } 51 52 53 // cont