“Input string was not in a correct format”

Thread is closed for posting
3 posts, 0 answers
  1. Sam
    Sam avatar
    2 posts
    Member since:
    Apr 2012

    Posted 17 Apr 2012 Link to this post

    I am getting the following Exception:

    "Input string was not in a correct format" on DataBind() line.

    I believe what is happening is that the poll is being created with numbers/integers and Telerik is being clever and treating them as ints instead of as strings.

    Is there a way to tell the telerik RadChart to either treat everything as strings or format things on a per entry basis?

    These two people have encountered a similar problem;

    http://www.telerik.com/community/forums/aspnet-ajax/chart/x-axis-values-mixed-strings-and-ints.aspx

    http://www.telerik.com/community/forums/wpf/chart/error-binding-string-value-to-x-axis-using-mvvm.aspx

    private void PopulatePollResults(int pollID)
       
    {
           
    SqlHelper sql = new SqlHelper();
           
    DataSet dsResults = sql.ExecuteDataSet("ReturnPollResults", pollID);

            dsResults
    .Tables[0].DefaultView.Sort = "AnswerID DESC";

            trcResults
    .DataSource = dsResults.Tables[0].DefaultView;
            trcResults
    .DataBind();

            trcResults
    .PlotArea.Appearance.Dimensions.Margins.Top = 10;
            trcResults
    .PlotArea.Appearance.Dimensions.Margins.Right = 5;
            trcResults
    .PlotArea.Appearance.Dimensions.Margins.Bottom = 10;
            trcResults
    .PlotArea.Appearance.Dimensions.Margins.Left = 177;


            lblNoOfVotes
    .Text = dsResults.Tables[1].Rows[0]["Count"].ToString() + " vote(s)";
       
    }
    <telerik:RadChart ID="trcResults" runat="server"
           
    ChartTitle-Visible="false"
           
    Legend-Visible="false"
           
    SeriesOrientation="Horizontal"
           
    Height="160px"
           
    Width="240px" >
           
    <Series>
               
    <telerik:ChartSeries DataYColumn="Votes"
                   
    DefaultLabelValue="#%">
                   
    <Appearance FillStyle-FillType="Solid"
                       
    FillStyle-MainColor="#660066"
                       
    Border-Visible="false"
                       
    TextAppearance-TextProperties-Font="Arial" >
                       
    <FillStyle FillType="Solid" MainColor="102, 0, 102">
                       
    </FillStyle>
                       
    <TextAppearance TextProperties-Font="Arial, 9pt">
                       
    </TextAppearance>
                       
    <Border Visible="False" />
                   
    </Appearance>
               
    </telerik:ChartSeries>
           
    </Series>
           
    <Appearance Border-Visible="False" FillStyle-FillType="Solid"
               
    FillStyle-MainColor="Transparent" Dimensions-AutoSize="false"
               
    Dimensions-Width="220px" Dimensions-Height="160px" >
               
    <FillStyle MainColor="Transparent">
               
    </FillStyle>
               
    <Border Visible="False" />
           
    </Appearance>
           
    <PlotArea>
               
    <YAxis2>
                   
    <AxisLabel>
                       
    <Appearance RotationAngle="0">
                       
    </Appearance>
                   
    </AxisLabel>
               
    </YAxis2>
               
    <Appearance FillStyle-FillType="Solid" FillStyle-MainColor="Transparent"
                   
    Border-Visible="False" >
                   
    <FillStyle FillType="Solid" MainColor="Transparent">
                   
    </FillStyle>
                   
    <Border Visible="False" />
               
    </Appearance>
               
    <XAxis DataLabelsColumn="AnswerText" IsZeroBased="False">
                   
    <Appearance MajorTick-Color="#333333"
                       
    TextAppearance-TextProperties-Color="#333333"
                       
    TextAppearance-TextProperties-Font="Arial" >
                       
    <TextAppearance TextProperties-Color="51, 51, 51"
                           
    TextProperties-Font="Arial, 8pt">
                       
    </TextAppearance>
                   
    </Appearance>
                   
    <AxisLabel>
                       
    <Appearance RotationAngle="270">
                       
    </Appearance>
                   
    </AxisLabel>
                   
    <Items>
                       
    <telerik:ChartAxisItem>
                           
    <TextBlock>
                               
    <Appearance TextProperties-Font="Arial, 8.25pt">
                               
    </Appearance>
                           
    </TextBlock>
                       
    </telerik:ChartAxisItem>
                       
    <telerik:ChartAxisItem Value="1">
                           
    <TextBlock>
                               
    <Appearance TextProperties-Font="Arial, 8.25pt">
                               
    </Appearance>
                           
    </TextBlock>
                       
    </telerik:ChartAxisItem>
                       
    <telerik:ChartAxisItem Value="2">
                           
    <TextBlock>
                               
    <Appearance TextProperties-Font="Arial, 8.25pt">
                               
    </Appearance>
                           
    </TextBlock>
                       
    </telerik:ChartAxisItem>
                       
    <telerik:ChartAxisItem Value="3">
                           
    <TextBlock>
                               
    <Appearance TextProperties-Font="Arial, 8.25pt">
                               
    </Appearance>
                           
    </TextBlock>
                       
    </telerik:ChartAxisItem>
                       
    <telerik:ChartAxisItem Value="4">
                           
    <TextBlock>
                               
    <Appearance TextProperties-Font="Arial, 8.25pt">
                               
    </Appearance>
                           
    </TextBlock>
                       
    </telerik:ChartAxisItem>
                       
    <telerik:ChartAxisItem Value="5">
                           
    <TextBlock>
                               
    <Appearance TextProperties-Font="Arial, 8.25pt">
                               
    </Appearance>
                           
    </TextBlock>
                       
    </telerik:ChartAxisItem>
                       
    <telerik:ChartAxisItem Value="6">
                           
    <TextBlock>
                               
    <Appearance TextProperties-Font="Arial, 8.25pt">
                               
    </Appearance>
                           
    </TextBlock>
                       
    </telerik:ChartAxisItem>
                       
    <telerik:ChartAxisItem Value="7">
                           
    <TextBlock>
                               
    <Appearance TextProperties-Font="Arial, 8.25pt">
                               
    </Appearance>
                           
    </TextBlock>
                       
    </telerik:ChartAxisItem>
                   
    </Items>
               
    </XAxis>
               
    <YAxis>
                   
    <Appearance Visible="false" />
                   
    <AxisLabel>
                       
    <Appearance RotationAngle="0">
                       
    </Appearance>
                   
    </AxisLabel>
               
    </YAxis>
           
    </PlotArea>
           
    <ChartTitle Visible="False">
               
    <Appearance Visible="False">
               
    </Appearance>
           
    </ChartTitle>
           
    <Legend Visible="False">
               
    <Appearance Visible="False">
               
    </Appearance>
           
    </Legend>
       
    </telerik:RadChart>

    I have mocked the db data as follows and the same issue is present.

    List<PollContainer> pcl = new List<PollContainer>();
            pcl.Add(new PollContainer(111, "1", 0));
            pcl.Add(new PollContainer(112, "2", 0));
            pcl.Add(new PollContainer(113, "3", 0));
            pcl.Add(new PollContainer(114, "4", 0));
            pcl.Add(new PollContainer(115, "5 - 10", 0));
            pcl.Add(new PollContainer(116, "10+", 0));
            trcResults.DataSource = pcl;
    trcResults.DataBind();
    
    ///////////////////////////////////////////////////////////////////
    List<PollContainer> pcl = new List<PollContainer>();
            pcl.Add(new PollContainer(111, "1d", 0));
            pcl.Add(new PollContainer(112, "2d", 0));
            pcl.Add(new PollContainer(113, "3", 0));
            pcl.Add(new PollContainer(114, "4", 0));
            pcl.Add(new PollContainer(115, "5 - 10", 0));
            pcl.Add(new PollContainer(116, "10+", 0));
            trcResults.DataSource = pcl;

    It seems Telerik doesn't like the strings "1" and "2"?!

    I have tried adding 
    Appearance-ValueFormat="General"
    
    to <XAxis>

    ref http://stackoverflow.com/questions/10177548/telerik-radchart-input-string-was-not-in-a-correct-format 

    Thanks,
  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 20 Apr 2012 Link to this post

    Hi Sam,

    The chart tries to predict the type of the data. And when the chart sees "1" and "2" it decides that all values will be integer. However, sometimes this is not the case.

    I can suggest that you attach handlers to DataBinding and BeforeLayout events and in the first prepend a sentinel symbol to all values and in the second remove the sentinel symbol:
    ...
     this.trcResults.DataBinding += this.trcResults_DataBinding;
     this.trcResults.BeforeLayout += this.trcResults_BeforeLayout;
     this.trcResults.DataSource = pcl;
     this.trcResults.DataBind();
    }
     
    void trcResults_DataBinding(object sender, EventArgs e)
    {
     var senderChart = (RadChart)sender;
     var pcl = senderChart.DataSource as IEnumerable<PollContainer>;
     
     foreach (var pollContainer in pcl)
     {
      // prepend a sentinel symbol
      pollContainer.AnswerText = "x" + pollContainer.AnswerText;
     }
    }
     
     
    void trcResults_BeforeLayout(object sender, EventArgs e)
    {
     foreach (var axisItem in this.trcResults.PlotArea.XAxis.Items)
     {
      // remove the sentinel symbol
      axisItem.TextBlock.Text = axisItem.TextBlock.Text.Remove(0, 1);
     }
    }

    Now the chart should always treat these values as text.

    I hope that this is a feasible solution for your project.

    Regards,
    Petar Marchev
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sam
    Sam avatar
    2 posts
    Member since:
    Apr 2012

    Posted 24 Apr 2012 Link to this post

    Hi,

    Thanks for your reply.

    I ended up swapping out the Telerik Poll with a Microsoft Chart based Poll as troubleshooting was taking too much time.

    I will go back and swap it now. :)
Back to Top