Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 663
  • Last Modified:

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.
0
vrodder
Asked:
vrodder
  • 2
1 Solution
 
DxpertCommented:
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
 
vrodderAuthor Commented:
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
 
vrodderAuthor Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now