473,385 Members | 1,375 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,385 software developers and data experts.

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 6657
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jeremy Chapman | last post by:
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,...
0
by: Vilmar Brazão de Oliveira | last post by:
Hi, I am having err when creating link to each line of grid at LINE 38. My objective in asp.net is: each line can be linked to page with your parameters as VB 5/6, Delphi 5/6/7, etc.... See the...
1
by: Dave | last post by:
Hello. Can anybody explain me how to use TemplateColumn?
0
by: Tigrou | last post by:
Hello, I'm searching for a solution who permit me to create an TemplateColumn in a DataGrid into codebehind... I found only solution for create it into the ASPX code... My problem is to find...
2
by: Tigrou | last post by:
Hello, I'm searching for a solution who permit me to create an TemplateColumn in a DataGrid into codebehind... I found only solution for create it into the ASPX code... My problem is to find...
1
by: David C | last post by:
I am trying to dynamically create a datagrid with code that looks exactly like what the asp tags show below. It has only one column and that column is a template column with a link button control....
0
by: tshad | last post by:
I have a custom object that handles my radio buttons. It works fine if I don't use it inside of a templatecolumn. But if I wrap it with the templateColumn/itemtemplate, it doesn't work at all. I...
3
by: rn5a | last post by:
A DataGrid has the following TemplateColumn: <asp:DataGrid ID="dgCart"...OnSortCommand="SortGrid" AllowSorting="true"....> <Column> <asp:TemplateColumn HeaderImageUrl="Images\Up.gif"...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.