469,927 Members | 1,820 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Unable to sort dynamically added templatefield to gridview

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 ?
Apr 19 '07 #1
2 10240
http://webswapp.com/codesamples/aspn.../gridview.aspx
--
HTH,
Phillip Williams
http://mcts-study-practices.com/
http://www.webswapp.com
"Carlo Marchesoni" wrote:
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 ?
Apr 20 '07 #2
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

"Phillip Williams" wrote:
http://webswapp.com/codesamples/aspn.../gridview.aspx
--
HTH,
Phillip Williams
http://mcts-study-practices.com/
http://www.webswapp.com
"Carlo Marchesoni" wrote:
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 ?
Apr 23 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by tfsmag | last post: by
1 post views Thread by =?Utf-8?B?Q2hyaXMgRmluaw==?= | last post: by
3 posts views Thread by =?Utf-8?B?Um9iZXJ0IFNtaXRo?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.