Professional Web Applications Themes

Creating TemplateColumns for a grid at runtime - ASP.NET General

At run time I've added a TemplateColumn to a DataGrid. Now I'm trying to add a Table control to the TemplateColumns's HeaderTemplate and ItemTemplate. In essence, I'm trying to do in code, the equilavent of this html: <asp:TemplateColumn> <HeaderTemplate> <asp:Table> <asp:TableRow> <asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell> </asp:TableRow> <asp:Table> </HeaderTemplate> <ItemTemplate> <asp:Table> <asp:TableRow> <asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell> </asp:TableRow> <asp:Table> </ItemTemplate> </asp:TemplateColumn>...

  1. #1

    Default Creating TemplateColumns for a grid at runtime

    At run time I've added a TemplateColumn to a DataGrid.

    Now I'm trying to add a Table control to the TemplateColumns's
    HeaderTemplate and ItemTemplate.

    In essence, I'm trying to do in code, the equilavent of this html:

    <asp:TemplateColumn>

    <HeaderTemplate>

    <asp:Table>

    <asp:TableRow>

    <asp:TableCell>

    </asp:TableRow>

    <asp:TableRow>

    <asp:TableCell>

    </asp:TableRow>

    <asp:Table>

    </HeaderTemplate>

    <ItemTemplate>
    <asp:Table>

    <asp:TableRow>

    <asp:TableCell>

    </asp:TableRow>

    <asp:TableRow>

    <asp:TableCell>

    </asp:TableRow>

    <asp:Table>

    </ItemTemplate>

    </asp:TemplateColumn>


    Jeremy Chapman Guest

  2. #2

    Default Re: Creating TemplateColumns for a grid at runtime

    I'm trying to do just that at the moment. It's a little involved. What you
    do is put everything between the <HeaderTemplate> and </HeaderTemplate> tags
    (not the tags) into an .ascx file, like a user control. Then
    you load that file into your template column.
    [url]http://www.dotnetbips.com/displayarticle.aspx?id=84[/url]

    Trouble is, I find this method really slow. There's an alternative which is
    even more complicated:
    [url]http://www.dotnetbips.com/displayarticle.aspx?id=85[/url]

    Let me know if you learn a way that performs well ...

    Good luck

    Justin Dutoit

    "Jeremy Chapman" <Nospamplease.com> wrote in message
    news:#jN9pIkUDHA.2456TK2MSFTNGP09.phx.gbl...
    > At run time I've added a TemplateColumn to a DataGrid.
    >
    > Now I'm trying to add a Table control to the TemplateColumns's
    > HeaderTemplate and ItemTemplate.
    >
    > In essence, I'm trying to do in code, the equilavent of this html:
    >
    > <asp:TemplateColumn>
    >
    > <HeaderTemplate>
    >
    > <asp:Table>
    >
    > <asp:TableRow>
    >
    > <asp:TableCell>
    >
    > </asp:TableRow>
    >
    > <asp:TableRow>
    >
    > <asp:TableCell>
    >
    > </asp:TableRow>
    >
    > <asp:Table>
    >
    > </HeaderTemplate>
    >
    > <ItemTemplate>
    > <asp:Table>
    >
    > <asp:TableRow>
    >
    > <asp:TableCell>
    >
    > </asp:TableRow>
    >
    > <asp:TableRow>
    >
    > <asp:TableCell>
    >
    > </asp:TableRow>
    >
    > <asp:Table>
    >
    > </ItemTemplate>
    >
    > </asp:TemplateColumn>
    >
    >

    Justin Dutoit Guest

  3. #3

    Default Re: Creating TemplateColumns for a grid at runtime

    I'm going to try the second solution. Looks like it could be a good one.

    "Justin Dutoit" <anonanon.com> wrote in message
    news:OZ8JFElUDHA.1916TK2MSFTNGP12.phx.gbl...
    > I'm trying to do just that at the moment. It's a little involved. What you
    > do is put everything between the <HeaderTemplate> and </HeaderTemplate>
    tags
    > (not the tags) into an .ascx file, like a user control. Then
    > you load that file into your template column.
    > [url]http://www.dotnetbips.com/displayarticle.aspx?id=84[/url]
    >
    > Trouble is, I find this method really slow. There's an alternative which
    is
    > even more complicated:
    > [url]http://www.dotnetbips.com/displayarticle.aspx?id=85[/url]
    >
    > Let me know if you learn a way that performs well ...
    >
    > Good luck
    >
    > Justin Dutoit
    >
    > "Jeremy Chapman" <Nospamplease.com> wrote in message
    > news:#jN9pIkUDHA.2456TK2MSFTNGP09.phx.gbl...
    > > At run time I've added a TemplateColumn to a DataGrid.
    > >
    > > Now I'm trying to add a Table control to the TemplateColumns's
    > > HeaderTemplate and ItemTemplate.
    > >
    > > In essence, I'm trying to do in code, the equilavent of this html:
    > >
    > > <asp:TemplateColumn>
    > >
    > > <HeaderTemplate>
    > >
    > > <asp:Table>
    > >
    > > <asp:TableRow>
    > >
    > > <asp:TableCell>
    > >
    > > </asp:TableRow>
    > >
    > > <asp:TableRow>
    > >
    > > <asp:TableCell>
    > >
    > > </asp:TableRow>
    > >
    > > <asp:Table>
    > >
    > > </HeaderTemplate>
    > >
    > > <ItemTemplate>
    > > <asp:Table>
    > >
    > > <asp:TableRow>
    > >
    > > <asp:TableCell>
    > >
    > > </asp:TableRow>
    > >
    > > <asp:TableRow>
    > >
    > > <asp:TableCell>
    > >
    > > </asp:TableRow>
    > >
    > > <asp:Table>
    > >
    > > </ItemTemplate>
    > >
    > > </asp:TemplateColumn>
    > >
    > >
    >
    >

    Jeremy Chapman Guest

  4. #4

    Default Re: Creating TemplateColumns for a grid at runtime

    It's OK now, tks

    Justin

    "Justin Dutoit" <anonanon.com> wrote in message
    news:esTNQXwUDHA.1928TK2MSFTNGP12.phx.gbl...
    > Would you help me with something- I'll show you the command-line compiler
    > line followed by the code... I'm missing a reference or a 'using'
    directive
    > which 'Container' needs, maybe you know which one...
    >
    > csc /out::..\bin\templatecolumns.dll /t:library /r:System.Data.dll
    > /r:System.dll /r:System.Web.dll ColumnTemplate.cs
    >
    >
    > ColumnTemplate.cs:
    >
    >
    > using System;
    > using System.Web.UI;
    > using System.Web.UI.WebControls;
    > using System.Data;
    >
    >
    > namespace Quickshop
    > {
    >
    > public class MyTemplateColumn:ITemplate
    > {
    > private string colname;
    >
    > public MyTemplateColumn(string cname)
    > {
    >
    > colname=cname;
    >
    > }
    >
    > /************************************************** *****************
    > ** As a template, the class must implement the following method **
    > ************************************************** *****************/
    >
    > public void InstantiateIn(Control container)
    > {
    >
    > LiteralControl l = new LiteralControl();
    > l.DataBinding +=
    > new EventHandler(this.OnDataBinding);
    > container.Controls.Add(l);
    >
    > }
    >
    >
    > public void OnDataBinding(object sender, EventArgs e)
    > {
    >
    > DataRowView mydataitem = (DataRowView)container.Dataitem;
    > LiteralControl l = (LiteralControl) sender;
    > DataGridItem container = (DataGridItem) l.NamingContainer;
    > l.Text = "<SPAN class=header>It is " +
    > ((DataRowView)container.DataItem)[colname].ToString() + "!</SPAN>";
    >
    > // l.Text = "<SPAN class=header>It si " +
    > // (mydataitem)["productnumber"].ToString() +
    > // (mydataitem)["brand"].ToString() +
    > // (mydataitem)["productname"].ToString() +
    > // (mydataitem)["price"].ToString() + "!</SPAN>";
    >
    >
    > }
    >
    > }
    >
    > }
    >
    >
    > Cheers
    > Justin
    >
    >
    >
    > "Jeremy Chapman" <Nospamplease.com> wrote in message
    > news:e3GZ#YsUDHA.1692TK2MSFTNGP11.phx.gbl...
    > > I'm going to try the second solution. Looks like it could be a good
    one.
    > >
    > > "Justin Dutoit" <anonanon.com> wrote in message
    > > news:OZ8JFElUDHA.1916TK2MSFTNGP12.phx.gbl...
    > > > I'm trying to do just that at the moment. It's a little involved. What
    > you
    > > > do is put everything between the <HeaderTemplate> and
    </HeaderTemplate>
    > > tags
    > > > (not the tags) into an .ascx file, like a user control. Then
    > > > you load that file into your template column.
    > > > [url]http://www.dotnetbips.com/displayarticle.aspx?id=84[/url]
    > > >
    > > > Trouble is, I find this method really slow. There's an alternative
    which
    > > is
    > > > even more complicated:
    > > > [url]http://www.dotnetbips.com/displayarticle.aspx?id=85[/url]
    > > >
    > > > Let me know if you learn a way that performs well ...
    > > >
    > > > Good luck
    > > >
    > > > Justin Dutoit
    > > >
    > > > "Jeremy Chapman" <Nospamplease.com> wrote in message
    > > > news:#jN9pIkUDHA.2456TK2MSFTNGP09.phx.gbl...
    > > > > At run time I've added a TemplateColumn to a DataGrid.
    > > > >
    > > > > Now I'm trying to add a Table control to the TemplateColumns's
    > > > > HeaderTemplate and ItemTemplate.
    > > > >
    > > > > In essence, I'm trying to do in code, the equilavent of this html:
    > > > >
    > > > > <asp:TemplateColumn>
    > > > >
    > > > > <HeaderTemplate>
    > > > >
    > > > > <asp:Table>
    > > > >
    > > > > <asp:TableRow>
    > > > >
    > > > > <asp:TableCell>
    > > > >
    > > > > </asp:TableRow>
    > > > >
    > > > > <asp:TableRow>
    > > > >
    > > > > <asp:TableCell>
    > > > >
    > > > > </asp:TableRow>
    > > > >
    > > > > <asp:Table>
    > > > >
    > > > > </HeaderTemplate>
    > > > >
    > > > > <ItemTemplate>
    > > > > <asp:Table>
    > > > >
    > > > > <asp:TableRow>
    > > > >
    > > > > <asp:TableCell>
    > > > >
    > > > > </asp:TableRow>
    > > > >
    > > > > <asp:TableRow>
    > > > >
    > > > > <asp:TableCell>
    > > > >
    > > > > </asp:TableRow>
    > > > >
    > > > > <asp:Table>
    > > > >
    > > > > </ItemTemplate>
    > > > >
    > > > > </asp:TemplateColumn>
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    Justin Dutoit Guest

Similar Threads

  1. Creating DataGrid at runtime
    By fastlife in forum Macromedia Flex General Discussion
    Replies: 3
    Last Post: July 21st, 04:08 AM
  2. Set column names to template grid at runtime
    By leewestcott@hotmail.com in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: February 11th, 06:13 PM
  3. Hidnig column in grid populated at runtime using DataSet
    By Sheikh Nabeel Moeen in forum ASP.NET Data Grid Control
    Replies: 3
    Last Post: December 17th, 06:58 AM
  4. adding validator control to editable data grid at runtime
    By Mark Siffer in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: June 21st, 04:33 PM
  5. Creating controls at runtime
    By geronimo in forum ASP.NET Building Controls
    Replies: 3
    Last Post: July 22nd, 06:53 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139