Error "Input string was not in a correct format." when trying to edit radgrid

2 posts, 0 answers
  1. kenghot
    kenghot avatar
    31 posts
    Member since:
    Feb 2007

    Posted 04 May 2009 Link to this post

    Hi,
       I use radgrid to edit data with sqldatasource. It works properly on IE7 but not firefox 3.0.10 . When i click edit button an error occure:
    The product that i use is "Radcontrols for asp.net Q7 2007"
    Server Error in '/' Application. 
    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) +7469351 
       System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119 
       System.Web.UI.WebControls.ImageButton.LoadPostData(String postDataKey, NameValueCollection postCollection) +163 
       System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +14 
       System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +693 
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1743 
     
     
    Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082  
    ProgramPage.aspx
    <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="ProgramPage.aspx.vb" Inherits="ProgramPage" title="KiDO : Program maintenance" %> 
    <%@ MasterType VirtualPath="~/MasterPage.master"  %> 
    <%@ Register Assembly="RadComboBox.Net2" Namespace="Telerik.WebControls" TagPrefix="radC" %> 
    <%@ Register Assembly="RadInput.Net2" Namespace="Telerik.WebControls" TagPrefix="radI" %> 
    <%@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="radG" %> 
    <%@ Register Assembly="RadEditor.Net2" Namespace="Telerik.WebControls" TagPrefix="radE" %> 
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"
     
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:cnKido %>" 
        SelectCommand="SELECT * FROM [Program]"  
        UpdateCommand="UPDATE Program SET ProgramCode=@ProgramCode ,ProgramName=@ProgramName ,ProgramDesc=@ProgramDesc ,IsCanceled=@IsCanceled ,UpdateUser=@UpdateUser ,UpdateDT=@UpdateDT  where ProgramKey=@ProgramKey " 
        InsertCommand="INSERT INTO Program( ProgramCode,ProgramName,ProgramDesc,IsCanceled,AddUser,UpdateUser,AddDT,UpdateDT) values (@ProgramCode,@ProgramName,@ProgramDesc,@IsCanceled,@AddUser,@UpdateUser,@AddDT,@UpdateDT)"
        <UpdateParameters> 
            <asp:Parameter Name="ProgramKey" Type="Int64" /> 
            <asp:Parameter Name="ProgramCode" Type="String" /> 
            <asp:Parameter Name="ProgramName" Type="String" /> 
            <asp:Parameter Name="ProgramDesc" Type="String" /> 
            <asp:Parameter Name="IsCanceled" Type="Boolean" /> 
            <asp:Parameter Name="UpdateUser" Type="String" /> 
            <asp:Parameter Name="UpdateDT" Type="datetime" /> 
        </UpdateParameters> 
        <InsertParameters> 
            <asp:Parameter Name="ProgramCode" Type="String" /> 
            <asp:Parameter Name="ProgramName" Type="String" /> 
            <asp:Parameter Name="ProgramDesc" Type="String" /> 
            <asp:Parameter Name="IsCanceled" Type="Boolean" /> 
            <asp:Parameter Name="AddUser" Type="String" /> 
            <asp:Parameter Name="UpdateUser" Type="String" /> 
            <asp:Parameter Name="AddDT" Type="datetime" /> 
            <asp:Parameter Name="UpdateDT" Type="datetime" /> 
        </InsertParameters> 
        </asp:SqlDataSource> 
        <br /> 
     
     
        <radG:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" 
            AllowAutomaticUpdates="True" AllowMultiRowSelection="True" 
            AllowPaging="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" 
            EnableAJAX="True" EnableAJAXLoadingTemplate="True" LoadingTemplateTransparency="50" 
            PageSize="14" ShowStatusBar="True" Width="97%" GridLines="None" AllowSorting="True"  AllowFilteringByColumn="True"
            <PagerStyle Mode="Slider" /> 
            <ClientSettings> 
                <Selecting AllowRowSelect="True" /> 
            </ClientSettings> 
            <MasterTableView CommandItemDisplay="Top" DataKeyNames="ProgramKey" 
                DataSourceID="SqlDataSource1" Width="100%"
                <CommandItemTemplate> 
                    <div style="padding: 10px 0px;"
                        &nbsp; 
                        <asp:LinkButton ID="btnCancel" runat="server" CausesValidation="false" CommandName="CancelAll" 
                            Visible='<%# RadGrid1.EditIndexes.Count > 0 Or RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="images/DataEditing/Img/Cancel.gif" /> Cancel editing</asp:LinkButton> 
                        &nbsp; 
                        <asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert" Visible='<%# Not RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="images/DataEditing/Img/AddRecord.gif" /> Add new </asp:LinkButton> 
     
                        &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; 
                        <asp:LinkButton ID="LinkButton4" runat="server" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="images/DataEditing/Img/Refresh.gif" /> Refresh list</asp:LinkButton> 
                    </div> 
                </CommandItemTemplate> 
               <Columns> 
                    <radG:GridEditCommandColumn ButtonType="ImageButton" CancelImageUrl="images/DataEditing/Img/Cancel.gif" 
                        EditImageUrl="images/DataEditing/Img/Edit.gif" InsertImageUrl="images/DataEditing/Img/Insert.gif" UpdateImageUrl="images/DataEditing/Img/Update.gif"
                        <HeaderStyle Width="30px" /> 
                    </radG:GridEditCommandColumn> 
                    <radG:GridTemplateColumn DataField="IsCanceled" DataType="System.Boolean" HeaderText="Cancel" 
                        SortExpression="IsCanceled" UniqueName="IsCanceled"
                        <ItemTemplate> 
                            <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("IsCanceled") %>' Enabled="False" /> 
                        </ItemTemplate> 
                    </radG:GridTemplateColumn> 
                <radG:GridBoundColumn DataField="ProgramCode" HeaderText="Code" SortExpression="ProgramCode" 
                UniqueName="ProgramCode"
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="ProgramName" HeaderText="Program Name" SortExpression="ProgramName" 
                UniqueName="ProgramName"
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="ProgramDesc" HeaderText="Description" SortExpression="ProgramDesc" 
                UniqueName="ProgramDesc"
                </radG:GridBoundColumn> 
     
               </Columns> 
                <EditFormSettings EditFormType="Template"
            
                    <FormTemplate> 
                        <asp:Label ID="lblKey" runat="server" Text='<%# Eval("ProgramKey") %>'></asp:Label> 
                        <table style="width: 100%"
                            <tr> 
                                <td style="text-align: center;"
                                    <table border="0" cellpadding="0" cellspacing="0" class="LoginOuterBox" style="width: 80%"
                                        <tr> 
                                            <td style="text-align: right"
                                                </td> 
                                            <td style="text-align: left;"
                                                <asp:CheckBox ID="chbIsCanceled" runat="server" Checked='<%# ScriptHelper.DBBoolean(Eval("IsCanceled")) %>' 
                                                    Text="Cancel" /></td
                                        </tr>   
                                  
                    <tr><td style="text-align: right"
                    <asp:Label ID="lblProgramCode" runat="server" Text="Program Code"></asp:Label></td
                    <td style="text-align: left;"
                    <asp:TextBox ID="txbProgramCode" runat="server" MaxLength="50" Text='<%# Bind("ProgramCode") %>' Width="336px"></asp:TextBox> 
                    </td></tr
                    <tr><td style="text-align: right; height: 38px;"
                    <asp:Label ID="lblProgramName" runat="server" Text="Program Name"></asp:Label></td
                    <td style="text-align: left; height: 38px;"
                    <asp:TextBox ID="txbProgramName" runat="server" MaxLength="100" Text='<%# Bind("ProgramName") %>' Width="336px"></asp:TextBox> 
                    </td></tr
                    <tr><td style="text-align: right; vertical-align: top;"
                    <asp:Label ID="lblProgramDesc" runat="server" Text="Description"></asp:Label></td
                    <td style="text-align: left;"
                    <asp:TextBox ID="txbProgramDesc" runat="server" MaxLength="200" Text='<%# Bind("ProgramDesc") %>' Width="336px" Height="112px" TextMode="MultiLine"></asp:TextBox> 
                    </td></tr
     
     
                                        <tr> 
                                            <td style="text-align: right"
                                            </td> 
                                            <td style="text-align: left"
                                                <asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="false" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>'
                                                <img style="border:0px;vertical-align:middle;" alt="" src="images/DataEditing/Img/Update.gif" /> Save </asp:LinkButton> 
                                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="Cancel"
                                                <img style="border:0px;vertical-align:middle;" alt="" src="images/DataEditing/Img/Cancel.gif" /> Cancel </asp:LinkButton> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                </td> 
                            </tr> 
                        </table> 
                    </FormTemplate> 
                    <EditColumn UniqueName="EditCommandColumn1"
                    </EditColumn> 
                </EditFormSettings> 
                <RowIndicatorColumn Visible="False"
                    <HeaderStyle Width="20px" /> 
                </RowIndicatorColumn> 
                <ExpandCollapseColumn Resizable="False" Visible="False"
                    <HeaderStyle Width="20px" /> 
                </ExpandCollapseColumn> 
            </MasterTableView> 
            <ExportSettings> 
                <Pdf PageBottomMargin="" PageFooterMargin="" PageHeaderMargin="" PageHeight="11in" 
                    PageLeftMargin="" PageRightMargin="" PageTopMargin="" PageWidth="8.5in" /> 
            </ExportSettings> 
        </radG:RadGrid> 
     
     
    </asp:Content> 
    ProgramPage.aspx.vb
    Imports ScriptHelper 
    Imports System.Data 
    Partial Class ProgramPage 
        Inherits System.Web.UI.Page 
     
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
            Me.RadGrid1.ClientSettings.ClientEvents.OnGridCreated = "" 
            If Not Page.IsPostBack Then 
                If Not (User.IsInRole("Admit") Or User.IsInRole("HQ")) Then 
                    Response.Redirect("./default.aspx") 
                End If 
            End If 
        End Sub 
        Private Sub SetSQlValue(ByVal ParameterName As String, ByVal ParameterValue As Object, ByVal IsADD As Boolean) 
            If IsADD Then 
                SqlDataSource1.InsertParameters(ParameterName).DefaultValue = ParameterValue 
            Else 
                SqlDataSource1.UpdateParameters(ParameterName).DefaultValue = ParameterValue 
            End If 
        End Sub 
        Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles RadGrid1.ItemCommand 
     
            Select Case e.CommandName 
                Case "Update" 
     
                    If Not CheckValid(e, False) Then 
                        e.Canceled = True 
                        Exit Sub 
                    End If 
                    SqlDataSource1.Update() 
                Case Telerik.WebControls.RadGrid.PerformInsertCommandName 
                    If Not CheckValid(e, True) Then 
                        e.Canceled = True 
                        Exit Sub 
                    End If 
                    SqlDataSource1.Update() 
                Case Telerik.WebControls.RadGrid.InitInsertCommandName 
                    RadGrid1.MasterTableView.ClearEditItems() 
                    e.Canceled = True 
                    Dim newValues As System.Collections.Specialized.ListDictionary = New System.Collections.Specialized.ListDictionary() 
                    newValues("IsCanceled") = False 
                    e.Item.OwnerTableView.InsertItem(newValues) 
                Case Telerik.WebControls.RadGrid.RebindGridCommandName 
                    RadGrid1.MasterTableView.ClearEditItems() 
                    For Each item As Telerik.WebControls.GridDataItem In RadGrid1.MasterTableView.Items 
                        item.OwnerTableView.IsItemInserted = False 
                    Next 
                Case Telerik.WebControls.RadGrid.EditCommandName 
                    RadGrid1.MasterTableView.ClearEditItems() 
     
            End Select 
        End Sub 
        
        Private Function CheckValid(ByVal e As Telerik.WebControls.GridCommandEventArgs, ByVal IsAdd As Boolean) As Boolean 
     
            Dim strErr As String = "" 
            Dim lbl As Label 
            lbl = e.Item.FindControl("lblProgramCode") 
            Dim txbProgramCode As TextBox = e.Item.FindControl("txbProgramCode") 
            If txbProgramCode.Text.Trim = "" Then 
                strErr &= "- Invalid " & lbl.Text & vbCrLf 
            End If 
            lbl = e.Item.FindControl("lblProgramName") 
            Dim txbProgramName As TextBox = e.Item.FindControl("txbProgramName") 
            If txbProgramName.Text.Trim = "" Then 
                strErr &= "- Invalid " & lbl.Text & vbCrLf 
            End If 
            lbl = e.Item.FindControl("lblProgramDesc") 
            Dim txbProgramDesc As TextBox = e.Item.FindControl("txbProgramDesc") 
            If txbProgramDesc.Text.Trim = "" Then 
                strErr &= "- Invalid " & lbl.Text & vbCrLf 
            End If 
            If strErr <> "" Then 
                DisplayMessage(strErr, RadGrid1) 
                Return False 
            End If 
            Master.MainData.ClearAllValue() 
            Master.MainData.AddSqlCommand("select * from Program where ProgramCode=@ProgramCode") 
            Master.MainData.AddParameter("@ProgramCode", txbProgramCode.Text) 
            Dim ds As DataSet = Master.MainData.GetDataset() 
            Dim lblKey As Label = e.Item.FindControl("lblKey") 
            If IsAdd Then 
                If ds.Tables(0).Rows.Count > 0 Then 
                    DisplayMessage("Code '" & txbProgramCode.Text & "' is already exist!", RadGrid1) 
                    Return False 
                End If 
            Else 
                If ds.Tables(0).Rows.Count > 0 AndAlso ds.Tables(0).Rows(0)("ProgramKey") <> Convert.ToInt64(lblKey.Text) Then 
                    DisplayMessage("Code '" & txbProgramCode.Text & "' is already exist!", RadGrid1) 
                    Return False 
                End If 
            End If 
            Dim chbIsCanceled As CheckBox = e.Item.FindControl("chbIsCanceled") 
            SetSQlValue("ProgramCode", txbProgramCode.Text, IsAdd) 
            SetSQlValue("ProgramName", txbProgramName.Text, IsAdd) 
            SetSQlValue("ProgramDesc", txbProgramDesc.Text, IsAdd) 
            SetSQlValue("UpdateUser", Membership.GetUser.ProviderUserKey.ToString, IsAdd) 
            SetSQlValue("UpdateDT", Now, IsAdd) 
            SetSQlValue("IsCanceled", chbIsCanceled.Checked, IsAdd) 
            If IsAdd Then 
                SetSQlValue("AddUser", Membership.GetUser.ProviderUserKey.ToString, IsAdd) 
                SetSQlValue("AddDT", Now, IsAdd) 
            Else 
                SetSQlValue("ProgramKey", Convert.ToInt64(lblKey.Text), IsAdd) 
            End If 
            Return True 
        End Function 
     
     
    End Class 
    BR,
    Kenghot
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 04 May 2009 Link to this post

    Hello Prachya,

    I suggest you upgrade to the latest version of RadControls for ASP.NET.AJAX (Q1 2009 SP1) and the issue under FireFox should be addressed. It appeared with version 3.0 of the browser and was fixed shortly after that by our developers in the subsequent release of the controls.

    Best wishes,
    Pavlina
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top