Home All Groups Group Topic Archive Search About
Author
12 Jun 2006 6:34 AM
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

Author
12 Jun 2006 2:18 PM
Julia
Hi

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

Any ideas?

/Julia

Show quoteHide quote
"Julia" wrote:

> 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
Author
13 Jun 2006 7:05 AM
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
Show quoteHide quote
"Julia" <Ju***@discussions.microsoft.com> ha scritto nel messaggio
news:05B39BEA-5EC8-439C-8FDC-959077D1C5F5@microsoft.com...
> Hi
>
> It is working when I use AutoGenerateColumns = true; but not when I use
> AutoGenerateColumns = false;.
>
> Any ideas?
>
> /Julia
>
> "Julia" wrote:
>
>> 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
Author
13 Jun 2006 2:55 PM
Riki
If you're using BoundColumns, don't forget to set the SortExpression
property for each column.

--

Riki

Show quoteHide quote
"Julia" <Ju***@discussions.microsoft.com> wrote in message
news:05B39BEA-5EC8-439C-8FDC-959077D1C5F5@microsoft.com...
> Hi
>
> It is working when I use AutoGenerateColumns = true; but not when I use
> AutoGenerateColumns = false;.
>
> Any ideas?
>
> /Julia
>
> "Julia" wrote:
>
>> 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