Creating TemplateColumn in Codebehind

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
Back
Top