Thanks Jeffery!

Once I worked out that sortOrder needed to be replaced with asc or desc I was 
on a roll. Easy when you know how. :)

Now...at the risk of pushing my luck...any idea what the name of the Column 
Group is and how to group by that to achieve the same look as 
_layouts/mngfield.aspx?

Regards,

Paul

From: [email protected] [mailto:[email protected]] On Behalf Of Jeffery Tsui
Sent: Tuesday, 25 August 2009 9:36 AM
To: [email protected]
Subject: RE: Sort SPGridView

Hi Paul,

You will have to sort with DataView.

DataView dv = tblSiteColumns.DefaultView;
dv.Sort = "columnName sortOrder";
grdSiteColumns.DataSource = dv;
grdSiteColumns.DataBind();

Cheers
Jeffery

From: [email protected] [mailto:[email protected]] On Behalf Of Paul Noone
Sent: Tuesday, 25 August 2009 9:19 AM
To: [email protected]
Subject: Sort SPGridView

Hi all,

I've got a simple system page which uses an SPGridView to display all site 
columns and their IDs.

Can anyone provide some advice on how to define the sort order? As an added 
bonus I'd also like to add the AllowPaging and AllowSorting functions. :)

Any help appreciated.

Regards,
Paul

8<----

protected override void OnLoad(EventArgs e)
{

    SPWeb web = SPContext.Current.Web;

    // Get role reference
    SPRoleDefinitionBindingCollection usersRoles = web.AllRolesForCurrentUser;
    SPRoleDefinitionCollection siteRoleCollection = web.RoleDefinitions;
    SPRoleDefinition roleDefinition = siteRoleCollection["Full Control"];

    if ((usersRoles.Contains(roleDefinition)) || web.CurrentUser.IsSiteAdmin)
    {
        //*******************************
        //Check if post back
        if (IsPostBack != true)
        {
            initPage();
        }
    }
    else
    {
        Response.Redirect("/_layouts/accessdenied.aspx");
    }
}
public void initPage()
{
    // Create a DataTable to hold our Site Column Data
    DataTable tblSiteColumns = new DataTable();
    tblSiteColumns.Columns.Add("ColumnName");
    tblSiteColumns.Columns.Add("ColumnID");
    tblSiteColumns.Columns.Add("ColumnDescription");

    // SPGridView
    // Create SPBoundField for each column
    SPBoundField fldNameField = new SPBoundField();
    fldNameField.DataField = "ColumnName";
    fldNameField.HeaderText = "Column Name";
    fldNameField.ItemStyle.Wrap = false;

    SPBoundField fldIDField = new SPBoundField();
    fldIDField.DataField = "ColumnID";
    fldIDField.HeaderText = "Column ID";
    fldIDField.ItemStyle.Wrap = false;

    SPBoundField fldDescriptionField = new SPBoundField();
    fldDescriptionField.DataField = "ColumnDescription";
    fldDescriptionField.HeaderText = "Column Description";

    // Add the columns to the grid
    grdSiteColumns.Columns.Add(fldNameField);
    grdSiteColumns.Columns.Add(fldIDField);
    grdSiteColumns.Columns.Add(fldDescriptionField);

    //Populate the DataTable
    foreach (SPField field in SPContext.Current.Web.Fields)
    {
        string[] rowValue = new string[3];
        rowValue[0] = field.Title;
        rowValue[1] = field.Id.ToString();
        rowValue[2] = field.Description;

        tblSiteColumns.Rows.Add(rowValue);
    }
    tblSiteColumns.AcceptChanges();

    //Bind the DataTable to the Grid
    grdSiteColumns.DataSource = tblSiteColumns;
    grdSiteColumns.DataBind();
    //*******************************************************
}


________________________________
Support procedure: https://www.codify.com/lists/support
List address: [email protected]
Subscribe: [email protected]
Unsubscribe: [email protected]
List FAQ: http://www.codify.com/lists/ozmoss
Other lists you might want to join: http://www.codify.com/lists
________________________________
Support procedure: https://www.codify.com/lists/support
List address: [email protected]
Subscribe: [email protected]
Unsubscribe: [email protected]
List FAQ: http://www.codify.com/lists/ozmoss
Other lists you might want to join: http://www.codify.com/lists
--------------------------------------------------------------------------------
Support procedure: http://www.codify.com/lists/support
List address: [email protected]
Subscribe: [email protected]
Unsubscribe: [email protected]
List FAQ: http://www.codify.com/lists/ozmoss
Other lists you might want to join: http://www.codify.com/lists

Reply via email to