2012-07-18 78 views
1

我正在使用這些代碼爲每行寫入標籤。如何按行中的自定義標籤對gridview進行排序

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

我的問題是:我怎樣才能使排序爲列[ 「cTotalValue」]使用lblPoint.Text?

回答

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; 
    } 
} 
相關問題