我有三个文本框txtOpeningAdv
,TxtAdvanceDeducted
,TxtClosingAdvance
的网格视图.....使用TxtAdvanceDeducted
上的KeyUp函数我计算TxtClosingAdvance
。 ..我的页面在TxtClosingAdvance
文本框中显示值...但是当我使用c#
访问它时,它会给我错误Input String was not in a correct format
...
当我通过萤火虫检查时,
<input type="text" class="text_box_height_14_width_50" id="ctl00_ContentPlaceHolder1_gridEmployee_ctl02_txtOpeningAdv" readonly="readonly" value="500.00" name="ctl00$ContentPlaceHolder1$gridEmployee$ctl02$txtOpeningAdv">
<input type="text" onkeyup="totalAmount(event,this);" autocomplete="off" class="text_box_height_14_width_50" id="ctl00_ContentPlaceHolder1_gridEmployee_ctl02_TxtAdvanceDeducted" name="ctl00$ContentPlaceHolder1$gridEmployee$ctl02$TxtAdvanceDeducted">
<input type="text" class="text_box_height_14_width_50" id="ctl00_ContentPlaceHolder1_gridEmployee_ctl02_TxtClosingAdvance" readonly="readonly" name="ctl00$ContentPlaceHolder1$gridEmployee$ctl02$TxtClosingAdvance">
这是我的gridview, alt text http://img90.imageshack.us/img90/7237/gridemp.jpg
我的c#代码,
foreach (GridViewRow row in gridEmployee.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
DataRow dr = dt.NewRow();
dr["EmpId"] = Convert.ToInt64(((HiddenField)row.Cells[0].FindControl("HiddenId")).Value);
dr["FromDate"] = Convert.ToDateTime(GetMonthNumberFromAbbreviation(fromdate[1].ToString()) + '/' + fromdate[0].ToString() + '/' + fromdate[2].ToString());
dr["ToDate"] = Convert.ToDateTime(GetMonthNumberFromAbbreviation(todate[1].ToString()) + '/' + todate[0].ToString() + '/' + todate[2].ToString());
dr["DaysPresent"] = Convert.ToDecimal(((TextBox)row.Cells[3].FindControl("TxtDaysPresent")).Text);//(row.Cells[4].Text);
dr["OpeningAdvance"] = Convert.ToDouble(((TextBox)row.Cells[4].FindControl("txtOpeningAdv")).Text);
dr["AdvanceDeducted"] = Convert.ToDouble(((TextBox)row.Cells[5].FindControl("TxtAdvanceDeducted")).Text);
dr["RemainingAdvance"] = Convert.ToDouble(((TextBox)row.Cells[6].FindControl("TxtClosingAdvance")).Text);
dr["SalaryGiven"] = Convert.ToDouble(((TextBox)row.Cells[7].FindControl("TxtSalary")).Text);
dr["CreatedDate"] = System.DateTime.Now;
dt.Rows.Add(dr);
}
}
错误在行,
dr["RemainingAdvance"] = Convert.ToDouble(((TextBox)row.Cells[6].FindControl("TxtClosingAdvance")).Text);
Input string was not in a correct format
但是我的gridview有TxtClosingAdvance="400.00"
...它是一个只读文本框,其值将放在TxtAdvanceDeducted
onkeyup event javascript ...
答案 0 :(得分:2)
作为猜测,您的字符串值为空或包含不需要的符号,如果它包含400.00而不是因为在服务器的区域设置中引起错误,请尝试检查((TextBox)row.Cells[6].FindControl("TxtClosingAdvance")).Text
的值“。”不是小数符号。如果它为空,则表示ASP.NET无法识别您的JavaScript更改。出于安全原因,ASP.NET会在响应时从VIEWSTATE恢复不可编辑的控件值,尝试通过设置EnableViewState = false
来禁用该控件的VIEWSTATE。
修改强>
顺便提一下,有一个ReadOnly TextBox问题已经讨论过here
希望这有帮助