Link to home
Start Free TrialLog in
Avatar of vrodder
vrodderFlag for United States of America

asked on

Helper function for databinder.eval returns conversion error

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.
Avatar of Dxpert
Dxpert
Flag of United States of America image

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;
    }
Avatar of vrodder

ASKER

When I take out the helper function and remove the string casting like:

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

It returns a number.
ASKER CERTIFIED SOLUTION
Avatar of vrodder
vrodder
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial