TemplateField in 2.0 // Disappears on Postback when TemplateField is added thru code

S

sloan

I am programmatically adding
BoundField's and
TemplateField's
to a GridView.

I have it working fine.

BoundField bf = new BoundField();
bf.DataField = "EmpID";
bf.HeaderText = "The Employee ID";
bf.SortExpression = "EmpID";
mygridview.Columns.Add(bf);


I know the TemplateFields are not as simply created, but I do have them
working.

TemplateField tf = new TemplateField();
tf.ItemTemplate = new // My Custom Implementation
tf.HeaderTemplate = new //My Custom Implementation

mygridview.Columns.Add(tf);




The issue arises when I do postbacks..namely the sorting or paging.

When I page or sort the gridview.. the PostBack occurs.

All of the bound field's I've added (programatically) are still there.

All the TemplateField's I add programatically disappear.

I've found a few "I have this issue" posts thru googling. But no answers.

Anybody have any ideas?

I've tried to find some property to enable viewstate for the TemplateField,
but its not natively there.



...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top