I have a SpGridView whit BoundFiled. I set a ObjectDataSource for it.

        sourceDataTable = new DataTable ();
        myDataTable = new DataTableWrapper(sourceDataTable);
        Type t = myDataTable.GetType();

        ObjectDataSource ds = new ObjectDataSource();
        ds.TypeName = t.AssemblyQualifiedName;
        ds.EnableViewState = false;
        ds.ID = "myDataSource";
        ds.SelectMethod = "GetTable";
        ds.ObjectCreating += new ObjectDataSourceObjectEventHandler(ds_ObjectCreating);

I created a DataTable with 3 columns. I fill it with name,number. and set for sourceDataTable.

When i sort SpGridView, name column sorting but number column don't sort.

I convert Number to string but don't sort.


It is difficult to troubleshoot since you didn't post all the code...

I would make sure your BoundField is setup correctly and the SortExpresssion property is being set to the correct column in your DataTable:

BoundField column = new BoundField();
column.DataField = name;
column.SortExpression = name;
column.HeaderText = name;

If that doesn't work, read Erik's wonderful blog post: Building A SPGridView Control – Part 1: Introducing the SPGridView.

| improve this answer | |
  • I use this code and set sortexpression for all column, but don't work. – ar.gorgin May 15 '12 at 3:39
  • Did you read the link I posted? Or, can you post the rest of our code? – Kit Menke May 15 '12 at 13:36
  • Yes, i use this link. – ar.gorgin May 15 '12 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.