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
260
WebDataGrid Adding new row throws "Input string was not in a correct format" error
posted

Hi, here is the behavior I'm attempting to produce:

  1. Click an "Add" button that creates a blank row in the WebDataGrid
  2. Fill out values in the row
  3. Retain values until next postback
  4. On postback, fire row_adding event to handle new data.

Everything works fine until I perform a postback. At that point I get this error:

Input string was not in a correct format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +14281985
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +305
   System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +859
   Infragistics.Web.UI.Framework.Data.DataBot.ChangeType(Object value, Type toType, CultureInfo culture) +449
   Infragistics.Web.UI.GridControls.EditingCore.OnAction(String actionType, Object id, Object value, Object tag) +11228
   Infragistics.Web.UI.GridControls.GridBot.LoadAdditionalClientState(Object state) +2329
   Infragistics.Web.UI.Framework.RunBot.HandleRaisePostDataChangedEvent() +144
   Infragistics.Web.UI.GridControls.GridBot.HandleRaisePostDataChangedEvent() +79
   System.Web.UI.Page.RaiseChangedEvents() +333
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3572

To create the row, I'm using using this code:

<input language="javascript" id="AddButton" onclick="return AddButton_onclick()"
type="button" value="Add" name="AddButton" runat="server" />

<script type="text/javascript" language="javascript" id="clientEventHandlersJS">
<!--

function AddButton_onclick() {
var grid = $find('<%= me.InfoGrid.ClientID %>');
var rows = grid.get_rows(); var rowsLength = rows.get_length();
// Create array of cell values for all values that cannot be null.
var row = new Array("", "", "", "", "", "");
// Add row.
rows.add(row);
var lastRow = rows.get_row(rowsLength); var cell = lastRow.get_cell(0); grid.get_behaviors().get_editingCore().get_behaviors().get_cellEditing().enterEditMode(cell);
}

//-->
</script>

Here is how the WebDataGrid is defined:

<ig:WebDataGrid ID="InfoGrid" runat="server" Height="350px" Width="400px"
                                    AutoGenerateColumns="False" DataKeyFields="ID">
                                    <Columns>
                                        <ig:BoundDataField DataFieldName="FIELDNAME1" Key="FIELDNAME1" DataType="System.String">
                                            <Header Text="FIELDNAME1" />
                                        </ig:BoundDataField>
                                        <ig:BoundDataField DataFieldName="FIELDNAME2" Key="FIELDNAME2" DataType="System.String">
                                            <Header Text="FIELDNAME2" />
                                        </ig:BoundDataField>
                                        <ig:BoundDataField DataFieldName="FIELDNAME3" Key="FIELDNAME3" DataType="System.String">
                                            <Header Text="FIELDNAME3" />
                                        </ig:BoundDataField>
                                        <ig:BoundDataField DataFieldName="FIELDNAME4" Key="FIELDNAME4" DataType="System.String">
                                            <Header Text="FIELDNAME4" />
                                        </ig:BoundDataField>
                                        <ig:BoundDataField DataFieldName="ID" Key="ID" DataType="System.Int32">
                                            <Header Text="ID" />
                                        </ig:BoundDataField>
                                        <ig:BoundDataField DataFieldName="FIELDNAME5" Key="FIELDNAME5" 
                                            DataType="System.String">
                                            <Header Text="FIELDNAME5" />
                                        </ig:BoundDataField>
                                    </Columns>
                                    <EditorProviders>
                                        <ig:TextBoxProvider ID="InfoGrid_TextBoxProviderInfo">
                                            <EditorControl ClientIDMode="Predictable"></EditorControl>
                                        </ig:TextBoxProvider>
                                        <ig:DropDownProvider ID="InfoGrid_DropDownProvider_FIELDNAME4">
                                            <EditorControl ClientIDMode="Predictable" DropDownContainerMaxHeight="200px" 
                                                EnableAnimations="False" EnableDropDownAsChild="False" 
                                                DataKeyFields="FIELDNAME4">
                                                <Items>
                                                    <ig:DropDownItem Selected="False" Text="VALUE1" Value="">
                                                    </ig:DropDownItem>
                                                    <ig:DropDownItem Selected="False" Text="VALUE2" Value="">
                                                    </ig:DropDownItem>
                                                    <ig:DropDownItem Selected="False" Text="VALUE3" Value="">
                                                    </ig:DropDownItem>
                                                    <ig:DropDownItem Selected="False" Text="VALUE4" Value="">
                                                    </ig:DropDownItem>
                                                </Items>
                                            </EditorControl>
                                        </ig:DropDownProvider>
                                        <ig:DropDownProvider ID="InfoGrid_DropDownProvider_Priority">
                                            <EditorControl ClientIDMode="Predictable" DropDownContainerMaxHeight="200px" 
                                                EnableAnimations="False" EnableDropDownAsChild="False">
                                                <Items>
                                                    <ig:DropDownItem Selected="False" Text="VALUE5" Value="">
                                                    </ig:DropDownItem>
                                                    <ig:DropDownItem Selected="False" Text="VALUE6" Value="">
                                                    </ig:DropDownItem>
                                                    <ig:DropDownItem Selected="False" Text="VALUE7" Value="">
                                                    </ig:DropDownItem>
                                                </Items>
                                            </EditorControl>
                                        </ig:DropDownProvider>
                                    </EditorProviders>
                                    <Behaviors>
                                        <ig:EditingCore BatchUpdating="True" >
                                            <Behaviors>
                                                <ig:CellEditing>
                                                    <ColumnSettings>
                                                        <ig:EditingColumnSetting ColumnKey="FIELDNAME1" 
                                                            EditorID="InfoGrid_TextBoxProviderInfo" />
                                                        <ig:EditingColumnSetting ColumnKey="FIELDNAME2" 
                                                            EditorID="InfoGrid_TextBoxProviderInfo" />
                                                        <ig:EditingColumnSetting ColumnKey="FIELDNAME3" 
                                                            EditorID="InfoGrid_TextBoxProviderInfo" />
                                                        <ig:EditingColumnSetting ColumnKey="FIELDNAME4" 
                                                            EditorID="InfoGrid_DropDownProvider_FIELDNAME4" />
                                                        <ig:EditingColumnSetting ColumnKey="FIELDNAME5" 
                                                            EditorID="InfoGrid_DropDownProvider_FIELDNAME5" />
                                                        <ig:EditingColumnSetting ColumnKey="ID" ReadOnly="True" />
                                                    </ColumnSettings>
                                                    <EditModeActions EnableOnActive="True" EnableOnKeyPress="True" />
                                                </ig:CellEditing>
                                                <ig:RowDeleting>
                                                </ig:RowDeleting>
                                                <ig:RowAdding>
                                                </ig:RowAdding>
                                            </Behaviors>
                                        </ig:EditingCore>
                                        <ig:Selection RowSelectType="Single">
                                        </ig:Selection>
                                        <ig:RowSelectors>
                                        </ig:RowSelectors>
                                        <ig:Activation>
                                        </ig:Activation>
                                    </Behaviors>
                                </ig:WebDataGrid>
Is my grid defined properly for this setup?
Note that it works if I use the built in Add Row behavior but I don't want my users to be tied to knowing they have to press enter to add the row.
Also, I'm handling the databinding in codebehind. I can post that as well but it works fine for loading and even for editing cells in the grid so I'm not sure if that's the problem.
Thanks