vicomin
asked on
calculate value for gridview label
i need to calculate the value and put in a gridview label. see the code.
error: Input string was not in a correct format.
error: Input string was not in a correct format.
protected void grdvw_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView drv = (DataRowView)e.Row.DataItem;
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblLabor = (Label)e.Row.FindControl("lblLabor");
string MainString = drv["reserved_isva"].ToString().Remove(0, 34);
string SearchString = " ";
int FirstChr = MainString.IndexOf(SearchString);
string cleanLabor = MainString.Remove(FirstChr);
lblLabor.Text = String.Format("{0:C2}", cleanLabor); //175.00
Label lblManHours = (Label)e.Row.FindControl("lblManHours");
lblManHours.Text = getMH(lblLabor.Text); //"175.00"
}
public static string getMH(string sLabor) //"175.00"
{
int iLabor = Convert.ToInt32(sLabor); //errors here
int iValue = iLabor / 60;
string sValue = Convert.ToString(iValue); //should equal "2.91666"
return sValue;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
slight modification
public static string getMH(string sLabor, string sQty) //"175.00", "2"
{
int iLabor = Convert.ToInt32(Convert.ToDecimal(sLabor));
int iQty = Convert.ToInt32(sQty);
int iValue = (iLabor * iQty);
string sValue = Decimal.Divide(iValue, 60).ToString();//5.8333333333333333333333333333
//round up so the above would be 6
return sValue;
}
may be you could use this function instead
public static string getMH(string sLabor) //"175.00"
{
double iLabor = Convert.ToDouble(sLabor); //errors here
double iValue = iLabor / 60.0;
string sValue = Convert.ToString(iValue); //should equal "2.91666"
return sValue;
}
public static string getMH(string sLabor) //"175.00"
{
double iLabor = Convert.ToDouble(sLabor); //errors here
double iValue = iLabor / 60.0;
string sValue = Convert.ToString(iValue); //should equal "2.91666"
return sValue;
}
ASKER
string sValue = System.Math.Round(Decimal. Divide(iVa lue, 60)).ToString();
int iLabor = Convert.ToInt32(Convert.To