Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Creating TemplateColumns for a grid at runtime

Reply
Thread Tools

Creating TemplateColumns for a grid at runtime

 
 
Jeremy Chapman
Guest
Posts: n/a
 
      07-25-2003
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>


 
Reply With Quote
 
 
 
 
Justin Dutoit
Guest
Posts: n/a
 
      07-25-2003
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.
http://www.dotnetbips.com/displayarticle.aspx?id=84

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

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

Good luck

Justin Dutoit

"Jeremy Chapman" <> wrote in message
news:#...
> 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>
>
>



 
Reply With Quote
 
 
 
 
Jeremy Chapman
Guest
Posts: n/a
 
      07-25-2003
I'm going to try the second solution. Looks like it could be a good one.

"Justin Dutoit" <> wrote in message
news:...
> 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.
> http://www.dotnetbips.com/displayarticle.aspx?id=84
>
> Trouble is, I find this method really slow. There's an alternative which

is
> even more complicated:
> http://www.dotnetbips.com/displayarticle.aspx?id=85
>
> Let me know if you learn a way that performs well ...
>
> Good luck
>
> Justin Dutoit
>
> "Jeremy Chapman" <> wrote in message
> news:#...
> > 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>
> >
> >

>
>



 
Reply With Quote
 
Justin Dutoit
Guest
Posts: n/a
 
      07-26-2003
It's OK now, tks

Justin

"Justin Dutoit" <> wrote in message
news:...
> 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" <> wrote in message
> news:e3GZ#...
> > I'm going to try the second solution. Looks like it could be a good

one.
> >
> > "Justin Dutoit" <> wrote in message
> > news:...
> > > 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.
> > > http://www.dotnetbips.com/displayarticle.aspx?id=84
> > >
> > > Trouble is, I find this method really slow. There's an alternative

which
> > is
> > > even more complicated:
> > > http://www.dotnetbips.com/displayarticle.aspx?id=85
> > >
> > > Let me know if you learn a way that performs well ...
> > >
> > > Good luck
> > >
> > > Justin Dutoit
> > >
> > > "Jeremy Chapman" <> wrote in message
> > > news:#...
> > > > 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>
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating TemplateColumns dynamically tshad ASP .Net 5 08-31-2007 08:04 AM
Adding TemplateColumns to a GridView GCeaser@aol.com ASP .Net 2 03-30-2006 08:39 PM
DataGrid TemplateColumns-- how-to use with CheckBoxes? Jim Bancroft ASP .Net 3 02-10-2005 12:32 AM
Problem with datagrid and TemplateColumns =?Utf-8?B?VGltOjouLg==?= ASP .Net 1 07-28-2004 12:52 PM
Dynamic TemplateColumns lose modified values on postback Pop ASP .Net Datagrid Control 0 02-04-2004 05:45 AM



Advertisments
 



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