简体   繁体   中英

Setting individual values in ASPxGridView

I have a ASPxGridView that gets populated from a database. Everything in my code works correctly (about 95% sure of this) and I essentially want to call

e.SetValue("MeanTime") = meanTimeCell;

Unfortunately this does not exist. I have searched for this but cannot find an answer.

protected void RTMonitoringGrid_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
     if (e.RowType == DevExpress.Web.GridViewRowType.Data) 
     {
        //this gets a value in the GridView 
        string meanTimeCell = e.GetValue("MeanTime").ToString();

        try
        {
           double result;
           if (double.TryParse(meanTimeCell, out result))
           {  
              //this is the string I essentially want to overwrite the old cell data with
              meanTimeCell = string.Format("{0}s", Math.Round(result, 1));
              //SetValue would be called here
           }
        }
        catch (Exception ex)
        {

        }
     }
}

Does anyone know an easy fix for this? I have thought of trying to format data before it gets put in the ASPxGridView but I think that would prove equally difficult.

Make an unbound column and handle the gridviews onCustomUnboundColumnData event. In that event, set the value to whatever you want it to be.

EDIT: actually since you only need to round the number from the database (if you are willing to drop the s on the end of it) Simply set the column's DisplayFormat.FormatType to "Numeric" and DisplayFormat.FormatString to display however many decimal places you want.

You could also follow the approach in the devexpress thread listed Here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM