[英]How to do sorting of field using DevExpress ASPxGridView
I have a Field Amount which should display curreny+ Amount. 我有一个字段金额,该字段应显示curreny +金额。 Since, I am not able to provide fieldName with '$'200 I have set the field as unbound.
从那时起,我无法为fieldName提供'$'200,因此我将该字段设置为未绑定。 Sorting happens but the data populated is not correct.
发生排序,但填充的数据不正确。 I have amount ranging from 40 to 500. But while sorting the descending order display 100 and ascending order displays 99.9 Kindly help to solve this issue.
我的数量从40到500不等。但是在对降序显示100和升序显示99.9进行排序时,请帮助解决此问题。
//Designer //设计师
<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>
//Code //码
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;
}
}
Please not that I have given value and displayText in 'gridReports_CustomColumnDisplayText' but sorting didnot take place.I had changed UnboundType to Integer and decimal also. 请不要在'gridReports_CustomColumnDisplayText'中给定值和displayText,但是排序没有进行。我也将UnboundType更改为Integer和十进制。
Tried this method also: 还尝试了此方法:
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());
}
}
The Amount field in dataset was string.Thus, lowest number was 1 and highest was 9 which caused the sorting issue. 数据集中的Amount字段为字符串,因此,最低编号为1,最高编号为9,这导致了排序问题。 Fixed the problem by converting the Amount field to decimal.
通过将“金额”字段转换为十进制来解决此问题。
//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);
}
Binded the Amount field directly with the grid view: 直接将“金额”字段与网格视图绑定:
<dx:GridViewDataColumn FieldName="AMOUNT" Caption="Amount" Width="100px" >
</dx:GridViewDataColumn>
For adding currency symbol binded the data in ColumnDisplayText method 要添加货币符号,请在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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.