Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. please help problem in creating template at run time.

please help problem in creating template at run time.

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasedesignhelptutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imranafsari
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups