code_junkie

How to grab control collection like the Table class does?

Nov 12th, 2011
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. <ME:NewControl ID="tblCustomList" runat="server">
  2. // ... these controls will be used in my UserControl.aspx
  3. </ME:NewControl>
  4.  
  5. <asp:Table ID="tblNormal" runat="server">
  6. <asp:TableRow>
  7. <asp:TableCell>Thing 1</asp:TableCell>
  8. <asp:TableCell>Thing 2</asp:TableCell>
  9. </asp:TableRow>
  10. </asp:Table>
  11.  
  12. <ME:NewControl ID="tblCustomList" runat="server">
  13. <asp:TableRow>
  14. <asp:TableCell>Thing 1</asp:TableCell>
  15. <asp:TableCell>Thing 2</asp:TableCell>
  16. </asp:TableRow>
  17. </ME:NewControl>
  18.  
  19. public TableRow DTHeader { get; set; }
  20.  
  21. protected override void OnInit(EventArgs e)
  22. {
  23. tblCollection.Rows.Add(DTHeader);
  24. base.OnInit(e);
  25. }
  26.  
  27. <ME:NewControl ID="tblCustomList" runat="server">
  28. <DTHeader>
  29. <asp:TableCell></asp:TableCell>
  30. //...
  31. </DTHeader>
  32. </ME:NewControl>
  33.  
  34. using System.Web;
  35. using System.Web.UI;
  36. using System.Web.UI.WebControls;
  37. using System.Security.Permissions;
  38.  
  39. namespace Samples.AspNet.CS.Controls
  40. {
  41. [AspNetHostingPermission(SecurityAction.Demand,
  42. Level = AspNetHostingPermissionLevel.Minimal)]
  43. public sealed class CustomTableCreateControlCollection : Table
  44. {
  45. protected override ControlCollection CreateControlCollection()
  46. {
  47. // Return a new ControlCollection
  48. return new ControlCollection(this);
  49. }
  50. }
  51. }
Add Comment
Please, Sign In to add comment