Creating TemplateColumns for a grid at runtime

Ask a Question related to ASP.NET General, Design and Development.

  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. Similar Questions and Discussions

    1. Creating DataGrid at runtime
      I would like to create a DataGrid with headers and empty cells (e.g. 4 colums) that are editable when the user, for example, clicks a button at...
    2. Set column names to template grid at runtime
      Hi all, I have datagrid on a C# webform. Users can choose a lookup table to read\ edit etc via selection from a dropdown list box. However I...
    3. Hidnig column in grid populated at runtime using DataSet
      Hello, I cant seem to find a property or method to hide the ID colum in a datagrid column which is populated using a DataSet at runtime (no...
    4. adding validator control to editable data grid at runtime
      I put this post up in framework.aspnet but it probably belongs here. The problem I am running into is that if you don't set those properties...
    5. Creating controls at runtime
      Hi, I am trying to create a TextBox at runtime, using the following code with a CodeBehind-File: Dim txtBox As New...
  3. #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" <Nospam@please.com> wrote in message
    news:#jN9pIkUDHA.2456@TK2MSFTNGP09.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

  4. #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" <anon@anon.com> wrote in message
    news:OZ8JFElUDHA.1916@TK2MSFTNGP12.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" <Nospam@please.com> wrote in message
    > news:#jN9pIkUDHA.2456@TK2MSFTNGP09.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

  5. #4

    Default Re: Creating TemplateColumns for a grid at runtime

    It's OK now, tks

    Justin

    "Justin Dutoit" <anon@anon.com> wrote in message
    news:esTNQXwUDHA.1928@TK2MSFTNGP12.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" <Nospam@please.com> wrote in message
    > news:e3GZ#YsUDHA.1692@TK2MSFTNGP11.phx.gbl...
    > > I'm going to try the second solution. Looks like it could be a good
    one.
    > >
    > > "Justin Dutoit" <anon@anon.com> wrote in message
    > > news:OZ8JFElUDHA.1916@TK2MSFTNGP12.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" <Nospam@please.com> wrote in message
    > > > news:#jN9pIkUDHA.2456@TK2MSFTNGP09.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

Posting Permissions

  • You may not post new threads
  • You may 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