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: 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