CMSDataGrid SortCommand

Alex Koshel asked on May 19, 2021 19:18

Hi. I create user control and add CMSDataGrid

   <cms:CMSDataGrid ID="CMSDataGrid1"
    AllowSorting="True"
    AutoGenerateColumns="False"
    CacheDependencies=""
    CacheMinutes="-1"
    CombineWithDefaultCulture="True"
    HideControlForZeroRows="False"
    RelationshipWithNodeGuid="00000000-0000-0000-0000-000000000000"
    SelectTopN="0"
    runat="server">
    <Columns>
        <asp:BoundColumn DataField="Title"
            HeaderText="Title"
            SortExpression="Title"/>
    </Columns>
    </cms:CMSDataGrid>  

behind have a code

 protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {                          
                CMSDataGrid1.DataSource = CreateDataSourse() ;
                CMSDataGrid1.DataBind();
            }

            CMSDataGrid1.SortCommand += new DataGridSortCommandEventHandler(Sort_Grid);

        }

        protected void Sort_Grid(object source, DataGridSortCommandEventArgs e)
        {
            DataTable dt = (DataTable)Session["Source"];

            DataView dv = new DataView(dt);

            dv.Sort = e.SortExpression;

            CMSDataGrid1.DataSource = dv;
            CMSDataGrid1.DataBind();
        }
        private DataView CreateDataSourse()
        {
            var documents = GetAllDocuments();
            var dataTable = ToDataTable(documents);
            Session["Source"] = dataTable;
            var dataView = new DataView(dataTable);

            return dataView;
        }

but when i click on sort dont run DataGridSortCommandEventHandler. Use kentico 11

Correct Answer

Alex Koshel answered on May 21, 2021 13:04

I change cms:CMSDataGrid to cms:BasicDataGrid and all work

0 votesVote for this answer Unmark Correct answer

Recent Answers


David te Kloese answered on May 21, 2021 09:12

Not sure if it's still an issue, but the only thing I could find about this is to make sure you've enabled viewstate.

I would assume you have, but perhaps it's just what was missing or that was purposely disabled:

"ViewState needs to be enabled for sorting."!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.