Solved

Helper function for databinder.eval returns conversion error

Posted on 2008-06-20
3
659 Views
Last Modified: 2012-05-05
Hello Experts.

I have a DropDownList inside a DataRepeater that looks like this:

              <asp:DropDownList runat="server" ID="ddlStat" SelectedValue=<%# funcLO(DataBinder.Eval(Container.DataItem, "ps_stat").ToString()) %> AppendDataBoundItems="true" >
                </asp:DropDownList>

The SelectedValue entry calls a helper function funcLO that looks like this:

    protected string funcLO(string strIn)
    {
        int intIn = int.Parse(strIn);
        int intOut = intIn - 1;
        string strOut = Convert.ToString(intOut);
        return strOut;
    }

Basically, all I want to do is subtract one from the SelectedValue that is returned from the DataBinder. When I run the code above I get a "Cannot convert type 'string' to 'int' error.

Thanks in advance.
0
Comment
Question by:vrodder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Expert Comment

by:Dxpert
ID: 21833890
Are you sure that you have a NUMBER in strIn?
What's the value of strIn?

protected string funcLO(string strIn)
    {
       response.write(strIn);
       response.end;
    }
0
 

Author Comment

by:vrodder
ID: 21833963
When I take out the helper function and remove the string casting like:

SelectedValue=<%# (DataBinder.Eval(Container.DataItem, "ps_stat") %>

It returns a number.
0
 

Accepted Solution

by:
vrodder earned 0 total points
ID: 21987508
I ended up keying off the SelectedIndex property instead of SelectedValue and eliminating the call to the helper function.  SelectedIndex was always 1 less than the SelectedValue, so it worked in this case, but who knows how I'll handle it if it comes up again.

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET - Refactor Class per SOLID principles 2 33
Is online banking safe? 11 90
Convert VB web project to C# 3 39
Validation for a field in asp.net 3 13
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this post we will learn different types of Android Layout and some basics of an Android App.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question