Two Comboboxes Error handling

6 posts, 0 answers
  1. berto
    berto avatar
    40 posts
    Member since:
    Jul 2012

    Posted 30 Jul 2013 Link to this post

    Example

    I have two Comboboxes:

    <telerik:RadComboBox ID="ddlPatientSuchwort2" Runat="server" Culture="de-DE"
      DataSourceID="sqlWinacsPatientSuchwort" DataTextField="Suchwort"
      DataValueField="PublicNummer" AutoPostBack="True"
      EnableAutomaticLoadOnDemand="True"
      onselectedindexchanged="ddlPatientSuchwort2_SelectedIndexChanged"
      filter="StartsWith" EmptyMessage="Patient Name" Skin="WebBlue"
      EnableVirtualScrolling="True" ItemsPerRequest="10"
        ShowMoreResultsBox="True" >
    </telerik:RadComboBox>
     
    <telerik:RadComboBox ID="ddlPublicNummer2" Runat="server" Culture="de-DE"
      DataSourceID="sqlWinacsPatientPublicNummer" DataTextField="PublicNummer"
      DataValueField="PublicNummer" AutoPostBack="True"
      EnableAutomaticLoadOnDemand="True"
      onselectedindexchanged="ddlPublicNummer2_SelectedIndexChanged"
      EmptyMessage="Patient Nummer" Label="oder" Skin="WebBlue"
      EnableVirtualScrolling="True" ItemsPerRequest="10"
        ShowMoreResultsBox="True" >
    </telerik:RadComboBox>

    protected void ddlPatientSuchwort2_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
     {
         int varPatient = int.Parse(ddlPatientSuchwort2.SelectedValue);
     
             ddlPublicNummer2.Text = "";
             ddlPublicNummer2.ClearSelection();
             this.getWinacsPatient(varPatient);
     
     }
     
     protected void ddlPublicNummer2_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
     {
         int varPatient = int.Parse(ddlPublicNummer2.SelectedValue);
     
             ddlPatientSuchwort2.Text = "";
             ddlPatientSuchwort2.ClearSelection();
             this.getWinacsPatient(varPatient);
     
     }


    Everything works fine when I select value. The problem happens
    when I write something in Combobox and don't choose value
    showed but click somwhere on the screen I got then:



    Server Error in '/Abrechnung' 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:

    Line 90:   protected void ddlPublicNummer2_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
    Line 91:   {
    Line 92:       int varPatient = int.Parse(ddlPublicNummer2.SelectedValue);
    Line 93: 
    Line 94:           ddlPatientSuchwort2.Text = "";

    Source File: d:\Dev\Abrechnung\Default.aspx.cs    Line: 92

    Stack Trace:

    [FormatException: Input string was not in a correct format.]
       System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +9595563
       System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
       System.Int32.Parse(String s) +23
       _Default.ddlPublicNummer2_SelectedIndexChanged(Object sender, RadComboBoxSelectedIndexChangedEventArgs e) in d:\Dev\Abrechnung\Default.aspx.cs:92
       Telerik.Web.UI.RadComboBox.OnSelectedIndexChanged() +215
       Telerik.Web.UI.RadComboBox.RaisePostDataChangedEvent() +63
       Telerik.Web.UI.RadDataBoundControl.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +34
       System.Web.UI.Page.RaiseChangedEvents() +134
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5201
    


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1008


    Any idea how I can handle this exceptions?
  2. A2H
    A2H avatar
    177 posts
    Member since:
    Mar 2010

    Posted 30 Jul 2013 Link to this post

    Hello,


    The reason for the error is when you load the data from data source, “DataValueField” and “DataTextField” is populated correctly.  However, when you type some random value, there is no DataValue for that particular option and in the selected index changed event RadComboBox’s  Datavalue will be null, hence system will throw error

    One suggestion is to check the “DataValueField” for null values before you parse it like given below. 

    protected void ddlPublicNummer2_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (ddlPublicNummer2.SelectedValue != "")
            {
                int varPatient = int.Parse(ddlPublicNummer2.SelectedValue);
            }
             
            ddlPatientSuchwort2.Text = "";
            ddlPatientSuchwort2.ClearSelection();
            this.getWinacsPatient(varPatient);
     
        }
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. berto
    berto avatar
    40 posts
    Member since:
    Jul 2012

    Posted 30 Jul 2013 Link to this post

    Thank you for your quick help. Now I am getting following:

    Fehler    8    The name 'varPatient' does not exist in the current context    d:\Dev\Abrechnung\Default.aspx.cs    88    33    d:\Dev\Abrechnung\

  5. A2H
    A2H avatar
    177 posts
    Member since:
    Mar 2010

    Posted 30 Jul 2013 Link to this post

    Hi,

    I apologize for providing you wrong code.

    Please modify your code like this

    protected void ddlPublicNummer2_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
       {
           int varPatient = 0;
           if (ddlPublicNummer2.SelectedValue != "")
           {
               varPatient = int.Parse(ddlPublicNummer2.SelectedValue);
           }
     
           ddlPatientSuchwort2.Text = "";
           ddlPatientSuchwort2.ClearSelection();
           this.getWinacsPatient(varPatient);
     
       }


    Thanks,
    A2H

  6. berto
    berto avatar
    40 posts
    Member since:
    Jul 2012

    Posted 31 Jul 2013 Link to this post

    Server Error in '/Abrechnung' 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:
     
     
    Line 60:       notPauschale = int.Parse(rbAPKnot.SelectedValue);
    Line 61:
    Line 62:       if (ddlPatientSuchwort2.Text != "") PatientNummer = int.Parse(ddlPatientSuchwort2.SelectedValue);
    Line 63:       else if (ddlPublicNummer2.Text != "") PatientNummer = int.Parse(ddlPublicNummer2.SelectedValue);
    Line 64:       else PatientNummer = 1;
      
     
    Source File: d:\Dev\Abrechnung\Default.aspx.cs    Line: 62
     
    Stack Trace:
     
     
    [FormatException: Input string was not in a correct format.]
       System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +9595563
       System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
       System.Int32.Parse(String s) +23
       _Default.Page_Load(Object sender, EventArgs e) in d:\Dev\Abrechnung\Default.aspx.cs:62
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnLoad(EventArgs e) +91
       System.Web.UI.Control.LoadRecursive() +74
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

    Still getting this error. To reproduce when I click on Combo box I am getting list: Patien1, Patient2 etc... When I write only "Pat" I am getting this error.
  7. A2H
    A2H avatar
    177 posts
    Member since:
    Mar 2010

    Posted 31 Jul 2013 Link to this post

    Hello,

    Can you please modify your code(line no 62 & 63) like this
    if (ddlPatientSuchwort2.SelectedValue != "") PatientNummer = int.Parse(ddlPatientSuchwort2.SelectedValue);
    else if (ddlPublicNummer2.SelectedValue != "") PatientNummer = int.Parse(ddlPublicNummer2.SelectedValue);

    Let me know if you face any concern.

    Thanks,
    A2H
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017