Solved

Helper function for databinder.eval returns conversion error

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A short article about problems I had with the new location API and permissions in Marshmallow
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

920 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

15 Experts available now in Live!

Get 1:1 Help Now