2014-06-05 73 views
1

我有一個應顯示curreny +金額的字段金額。因爲,我無法提供'$'200的fieldName我已經設置爲未綁定的字段。發生排序但填充的數據不正確。我有數量從40到500.但排序降序顯示100和升序顯示99.9 請幫助解決此問題。如何使用DevExpress ASPxGridView對字段進行排序

//設計師

<dx:ASPxGridView ID="gridReports" runat="server" Width="100%" KeyFieldName="SID" ClientInstanceName="gridReports" 
onpageindexchanged="gridReports_PageIndexChanged" onrowcommand="gridReports_RowCommand" AutoGenerateColumns="False" oncustomunboundcolumndata="gridReports_CustomUnboundColumnData" oncustomcolumndisplaytext="gridReports_CustomColumnDisplayText"> 
<SettingsBehavior EnableRowHotTrack="true" /> <SettingsPager AlwaysShowPager="true" Position="Bottom" PageSize="25" /> 
<Columns> 
<dx:GridViewDataColumn CellStyle-HorizontalAlign="right" Width="24%" Caption="AMOUNT" VisibleIndex="5" UnboundType="Decimal" FieldName="ForeName" Settings-SortMode="Value"> 
</Columns> 
<SettingsBehavior ConfirmDelete="True" /> <SettingsBehavior ConfirmDelete="True" EnableRowHotTrack="True" /> <SettingsPager AlwaysShowPager="True" PageSize="25"> </SettingsPager> 

//代碼

protected void gridReports_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs e) 
     { 
      if (e.Column.FieldName == "ForeName") 
      { 
       string currency = (string)e.GetListSourceFieldValue("DEFAULT_CURRENCY"); 
       string amount = (string)e.GetListSourceFieldValue("AMOUNT"); 
       e.Value = GTYPE(currency) + amount; 

      } 
     } 

請不,我已經給定值和displayText在 'gridReports_CustomColumnDisplayText' 但分揀因此未採取place.I已經改變UnboundType整數和小數。

試過這種方法也:

protected void gridReports_CustomColumnDisplayText(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDisplayTextEventArgs e) 
     { 
      if (e.Column.FieldName == "ForeName") 
      { 
       object currency = e.GetFieldValue("DEFAULT_CURRENCY"); 
       object amount = e.GetFieldValue("AMOUNT"); 
       e.DisplayText = ((string)GTYPE(currency.ToString()) + amount); 
       e.Value = Decimal.Parse(amount.ToString()); 


      } 
     } 
+0

請張貼的所有代碼爲您dxGridView – BossRoss

+1

@ BossRoss:感謝您的時間來解決這個問題。找到解決方案,並在下面發佈。 – psobhan

回答

2

在數據集的金額字段是string.Thus,最低人數是1和最高爲9造成分揀的問題。通過將「數量」字段轉換爲十進制來修復此問題。

//Code added for sorting Amount field: 

    if (ds != null) 
    { 

     DataTable dtCloned = ds.Tables[0].Clone(); 
     dtCloned.Columns["AMOUNT"].DataType = typeof(decimal); 
     foreach (DataRow row in ds.Tables[0].Rows) 
     { 
      dtCloned.ImportRow(row); 
     } 
     ds = null; 
     ds = new DataSet(); 
     ds.Tables.Add(dtCloned); 
    } 

綁定金額字段直接與網格視圖:

<dx:GridViewDataColumn FieldName="AMOUNT" Caption="Amount" Width="100px" > 
</dx:GridViewDataColumn> 

對於增加貨幣符號綁定的數據ColumnDisplayText方法

protected void gridReports_CustomColumnDisplayText(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDisplayTextEventArgs e) 
     { 
      if (e.Column.FieldName == "AMOUNT") 
      { 
       object currency = e.GetFieldValue("DEFAULT_CURRENCY"); 
       object amount = e.GetFieldValue("AMOUNT"); 
       e.DisplayText = ((string)GTYPE(currency.ToString()) + amount); 

      } 
     } 
相關問題