Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
570
Set DataFormatString in server-side code for a specific cell
posted

 Is there a way to set the DataFormatString in server-side code?  I would like to see if it is possible to set the DataFormatString of a specific cell.  I see an attribute FormatFieldMethod but dont understand how to set/change it.  Thanks.

Parents
No Data
Reply
  • 19308
    posted

    The FormatFieldMethod takes a delegate of type FormatRecordItemValue.  Basically this means that you get to define a method that will be called each time a cell is processed and you will have the opportunity to format the text.  Here's an example which just returns "hello" as the formatted text for a column.  There's no way to tell what row-index the cell is for, so you'll have to rely on the "value" parameter, and look for the string you want to format.  Alternatively, you could add a counter in the "Format" method which you could use to keep track of how many times Format was called - which should be the same as the index of the row ..

    protected void Page_Load(object sender, EventArgs e)
    {
        this
    .WebDataGrid1.Columns[0].FormatFieldMethod = new FormatRecordItemValue(Format);
    }
     
    protected string Format(ControlDataField field, object value)
    {
        return "hello";
    }

     

Children