1

我正在使用这些代码为每一行编写标签。

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"
}

我的问题是:如何使用 lblPoint.Text 为 Column["cTotalValue"] 启用排序?

4

1 回答 1

1

ASPxGridView 有一个可以实现的事件,称为 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;
    }
}
于 2012-07-26T23:18:18.657 回答