Solved

Helper function for databinder.eval returns conversion error

Posted on 2008-06-20
3
655 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Editing XSL files, 2 21
Need an intro to -- .Net SQL Authorization Manager 7 47
Chat Room 1 25
Base1 Encode/Decode 3 29
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

708 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now