I'm trying to set default values in the WebDataGrid if the Cell is null or does not contain a value. I am trying to do this check in the WebDataGrid InitializeRow server-side event, however, do not have a method for setting the value of a particular cell. Is the data bound at this point ? If so, what is the command I should use to set the value.
The WebDataGrid acts as a view on top of a model. In this case the model is your underlying data. Rather than editing the data through the grid, you should edit it through your data tier. So insetad of trying to set a grid cell's value, you should be setting the value in your underlying datasource.
Understood. One problem I am encountering is that if I format the column DataFormatString to Percent, and prefill the field during databinding, I need to use decimal format (eg. 1.0 = 100%). However, when the user clicks on an empty field, if he puts in 1.0, the formatting converts that to 1%. Why is there a difference? Is this a bug?
Hello,
Weird, I cannot reproduce that. What is the DataFormatString you are using and the date you are binding against? Here is what I am using and both at runtime and after user entry (EditingCore -> Cell Editing is enabled) the behaviour is correct, e.g. 1 gets converted correctly to 100%
<ig:BoundDataField DataFieldName="EmployeeID" Key="EmployeeID" DataFormatString="{0:P}"> <Header Text="EmployeeID" />
Actually I removed the WebPercentEditProvider binding and it still has the same problem with {0:P1}.
In the aspx, I'm using:
<ig:BoundDataField CssClass="GridCellData" DataFieldName="OCT" Key="OCT" Width="50px" DataFormatString="{0:P1}"> </ig:BoundDataField>
Then in the code behind:
Dim DTgridview As New DataTable("Meals") DTgridview.Columns.Add(New DataColumn("MealsType", GetType(String))) DTgridview.Columns.Add(New DataColumn("OCT", GetType(Double))) DTgridview.Columns.Add(New DataColumn("NOV", GetType(Double))) DTgridview.Columns.Add(New DataColumn("DEC", GetType(Double))) DTgridview.Columns.Add(New DataColumn("JAN", GetType(Double))) DTgridview.Columns.Add(New DataColumn("FEB", GetType(Double))) DTgridview.Columns.Add(New DataColumn("MAR", GetType(Double))) DTgridview.Columns.Add(New DataColumn("APR", GetType(Double))) DTgridview.Columns.Add(New DataColumn("MAY", GetType(Double))) DTgridview.Columns.Add(New DataColumn("JUN", GetType(Double))) DTgridview.Columns.Add(New DataColumn("JUL", GetType(Double))) DTgridview.Columns.Add(New DataColumn("AUG", GetType(Double))) DTgridview.Columns.Add(New DataColumn("SEP", GetType(Double))) DTgridview.Columns.Add(New DataColumn("Total", GetType(Double))) Dim datarow As DataRow = DTgridview.NewRow() datarow = DTgridview.NewRow() datarow("MealsType") = "Breakfast" datarow("OCT") = 1
DTgridview.Rows.Add(datarow) WebDataGrid1.DataSource = DTgridview
Hi,
Unfortunately WebPercentEdit class which is used by WebPercentEditProvider does not convert 1 to 100%, but uses numeric values as they are. So, when grid sets initial value of edtior to "1", then it is used as 1.0, but not as 100.0. On end edit mode WebPercentEdit returns same numeric value 1.0, but not 0.01.
Currently WebPercentEditProvider can not be used with {0:P} format string, but only {0:n}. Support for {0:P} should be a feature request. I think that it will be implemented in future versions.
I am using DataFormatString="{0:P1}" but I am also set the the Behavior for ColumnSetting to a WebPercentEditProvider
<EditorProviders> <ig:WebPercentEditProvider ID="PercentProvider" DataMode="Decimal" MinDecimalPlaces="One" MinValue="0" MaxValue="999.9"/> </EditorProviders>
<Behaviors> <ig:EditingCore> <Behaviors> <ig:CellEditing EditCellCssClass="EditCell"> <EditModeActions MouseClick="Single" EnableOnActive="True" EnableOnKeyPress="True" /> <CellEditingClientEvents ExitedEditMode="WebDataGridView_ExitedEditMode" /> <ColumnSettings> <ig:EditingColumnSetting ColumnKey="OCT" EditorID="PercentProvider" /> </ColumnSettings> </ig:CellEditing> </Behaviors> </ig:EditingCore> </Behaviors>
<Columns> <ig:BoundDataField CssClass="GridCellData" DataFieldName="OCT" Key="OCT" Width="50px" DataFormatString="{0:P1}"> <Header Text="OCT" /> </ig:BoundDataField> </Columns>