Mehmet Emre Portakal
Mehmet Emre Portakal

Reputation: 1784

How to sort gridview by custom label in the row

I am using these codes to write label for each row.

protected void grd_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e)
{
ASPxLabel lblPoint = grd.FindRowCellTemplateControl(e.VisibleIndex, grdBildiriler.Columns["cTotalValue"] as GridViewDataColumn, "lblPoint") as ASPxLabel;
lblPoint.text = "a value different for each row"
}

My question is : How can I enable sorting for Column["cTotalValue"] using lblPoint.Text ?

Upvotes: 1

Views: 1014

Answers (1)

kmc059000
kmc059000

Reputation: 3067

The ASPxGridView has an event you can implement called CustomColumnSort. http://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridViewASPxGridView_CustomColumnSorttopic

protected void grid_CustomColumnSort (object sender, DevExpress.Web.ASPxGridView.CustomColumnSortEventArgs e) {
    if (e.Column.FieldName == "cTotalValue") 
    {
        e.Handled = true;

        //you can get the row index of 2 columns being sorted through e.ListSourceRowIndex1 and e.ListSourceRowIndex2
        //Get the two custom values and compare and set result

        var value1 = "Some custom value you retrieve using e.ListSourceRowIndex1";
        var value2 = "Another custom value you retrieve using e.ListSourceRowIndex2";

        if (value1 > value2)
            e.Result = 1;
        else if (value1 == value2)
            e.Result = Comparer.Default.Compare(value1, value2);
        else
            e.Result = -1;
    }
}

Upvotes: 1

Related Questions