Unable to sort dynamically added templatefield to gridview

G

Guest

I am building a GridView dynamically adding templatFields according to a
Microsoft article. I had to create a class with the ITemplate interface and a
method called InstantiateIn.
Everything works fine except that I am unable to sort such a templatefield.
AllowSorting is true:
<asp:GridView ID="gvwPend" runat="server"
AllowSorting="True"
AutoGenerateColumns="False"
...
OnSorting="gvwPend_Sorting">
and I dynamically set SortExpression :
TemplateField tc = new TemplateField();
tc.SortExpression = "test";
tc.HeaderTemplate =
new MyDataGridTemplate(MyDataGridTemplate.Header, "MyHeader"));
tc.ItemTemplate =
new MyDataGridTemplate(MyDataGridTemplate.Item, "");

Running the code doesn't show the header with underlines and clicking on it
does not run gvwPend_Sorting.
What am I doing wrong ?
 
G

Guest

Thank you for your reply - you have an interesting site.
As far as I can see from code the difference is, that you create the
HeaderText straight away and not from a Template as I did.
Just two questions on this:
a) I don't find the _Sorting event in your code, but I guess this would be
fired if trapped - is this correct ?
b) can I see your definition of the <HeaderStyle
CssClass="ITemplateGVHeader" /> style somewhere on your page ?
Thanks a lot for your help
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top