vrodder
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(Con tainer.Dat aItem, "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.
I have a DropDownList inside a DataRepeater that looks like this:
<asp:DropDownList runat="server" ID="ddlStat" SelectedValue=<%# funcLO(DataBinder.Eval(Con
</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.
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.
SelectedValue=<%# (DataBinder.Eval(Container
It returns a number.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What's the value of strIn?
protected string funcLO(string strIn)
{
response.write(strIn);
response.end;
}