sorting in a datagrid

J

Julia

Hi,

I am developing a composite control, so I am writing all my code in a *.cs
file. One of the component in my composite control is a datagrid. The
datagrid is populated from a dataview by using DataBind(). The user should be
able to sort the datagrid my clicking the header of the columns. Anyone has
a sample of this? It would be really helpful for me. I only want to write c#
code to do this.

Thanks
Julia
 
J

Julia

Hi

It is working when I use AutoGenerateColumns = true; but not when I use
AutoGenerateColumns = false;.

Any ideas?

/Julia
 
A

Alessandro Zifiglio

hi Julia,
you need to attach to the SortCommand handler for your datagrid in code and
then do what you need to do in this event when sorting is enabled on the
grid. One possible mistake i can think of why you sorting is not working on
your grid is possibly because when you set autogenerate columns to false,
you are probably also trying to set a templatecolumn in the HeaderTemplate
<HeaderTemplate></HeaderTemplate> . In this case make sure you add a control
in your HeaderTemplate that can postback like a button control or a
linkbutton, imagebutton etc..
try these resources :
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.allowsorting.aspx

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.sortcommand.aspx

good luck,
Alessandro Zifiglio
 
R

Riki

If you're using BoundColumns, don't forget to set the SortExpression
property for each column.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top