473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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>
Nov 17 '05 #1
3 2618
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" <No****@please.com> wrote in message
news:#j**************@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>

Nov 17 '05 #2
I'm going to try the second solution. Looks like it could be a good one.

"Justin Dutoit" <an**@anon.com> wrote in message
news:OZ**************@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.
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" <No****@please.com> wrote in message
news:#j**************@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>


Nov 17 '05 #3
It's OK now, tks

Justin

"Justin Dutoit" <an**@anon.com> wrote in message
news:es**************@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" <No****@please.com> wrote in message
news:e3**************@TK2MSFTNGP11.phx.gbl...
I'm going to try the second solution. Looks like it could be a good one.

"Justin Dutoit" <an**@anon.com> wrote in message
news:OZ**************@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.
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" <No****@please.com> wrote in message
news:#j**************@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>
>
>



Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: owen | last post by:
Generally speaking, what does it mean when I see a "button" with red text showing this message instead of the control I've dragged onto the web form in Design View.? (But the page works fine at...
2
by: dfreas | last post by:
I'm using Bloodshed Dev-C++ to write a program used to calculate orders for my business. Until recently a command line program has been sufficient but it is beginning to become cumbersome so I've...
3
by: Darleen | last post by:
I am seeking conceptual here on how to get started with a "3D Matrix" in Access. We run a training center which holds multiple classes in multiple cities at multiple times. So I need to create a...
4
by: Filippo Pandiani | last post by:
I have a grid that shows the file list from a folder. On the postback, how do I get a Dataset from this grid? Thanks, Filippo.
4
by: Carlos Lozano | last post by:
Hello Folks! I have a grid that populates from a table on SQL Server. All datetime with DBNull value show 1/1/1900 12:00AM ... Instead of just blank (""). I found a document with the following...
1
by: Tim::.. | last post by:
Hi can someone tell me how I get the values from a datagrid using template columns??? I tried like this but I keep getting Input string was not in a correct format. I don't think I'm doing this...
3
by: Tony Johansson | last post by:
Hello!! We are using .NET C# so the product must use this language. The existing controls within .NET is not good enough so I'm looking and evaluating other products. We need a product to...
1
by: ben m | last post by:
Hi all - we've recently switched up to 2005, and I'm having trouble getting the hang of some things, among them, creating a control for the project. Currently, we use a combination of controls on a...
5
by: tshad | last post by:
I found I can create Template columns dynamically - as long as I don't use objects that need onclick events, such as a LinkButton. Textboxes and Labels work fine. I create the Template columns...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.