469,267 Members | 998 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

Creating TemplateColumn in Codebehind

Hi,
I need to create DataGrid with TemplateColumns in Codebehind
so I do something like that:

TemplateColumn templateColumn = new TemplateColumn();
templateColumn.HeaderText = "header title";
TemplateBuilder templateBuilder = new TemplateBuilder();
templateBuilder.AppendLiteralString("text" );
templateColumn.ItemTemplate = templateBuilder;
DataGrid1.Columns.Add(templateColumn);
so I have new column with "text" string in every row of this column. How
could I define, so I will have in this column some literal text, as this
"text" and also data from DataSet which I've bound to DataGrid1... when I try
to:
templateBuilder.AppendLiteralString("<%# DataBinder.Eval(Container.DataItem,
\"columnName\") %> text" );
it dosen't work as I want to, becouse .NET treaded this like literal control.

Regards,
Krzysztof Karnicki
Nov 16 '05 #1
3 6478
Hi, TemplateBuilder is a Siren, she lures you into the rocks and then
irritates you as you try and fail to get it to work...!

Check out this
http://msdn.microsoft.com/library/de...mmatically.asp

It's really much simpler than it first looks, basically you hard code
your databinds into the InstantiateIn override.
Jim

Nov 16 '05 #2
He is asking about a completely different thing
<jd*******@shaw.ca> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi, TemplateBuilder is a Siren, she lures you into the rocks and then
irritates you as you try and fail to get it to work...!

Check out this
http://msdn.microsoft.com/library/de...mmatically.asp
It's really much simpler than it first looks, basically you hard code
your databinds into the InstantiateIn override.
Jim

Nov 16 '05 #3
No - I dont think he is asking about a completely different thing. My
understanding is, he's asking how you get TemplateBuilder to
'recognize' or work with databound values - quote;

"How could I define, so I will have in this column some literal text,
as this
"text" and also data from DataSet which I've bound to DataGrid1... when
I try
to: templateBuilder.AppendLiteralString("<%#
DataBinder.Eval(Container.DataItem,
\"columnName\") %> text" ); "

The article I posted shows how to solve this, I know because I had just
been searching for a solution to the same problem, and after I found
the solution I was nice and posted the solution to the most recent
question on usenet/google-groups, because I hadn't found the solution
on there.

Maybe if you have a different interpretation of his question, you'd
like to share it?

Jim

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jeremy Chapman | last post: by
reply views Thread by Vilmar Braz„o de Oliveira | last post: by
1 post views Thread by Dave | last post: by
1 post views Thread by David C | last post: by
reply views Thread by tshad | last post: by
5 posts views Thread by tshad | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.