2010-02-26 22 views
0

我有三個文本框txtOpeningAdvTxtAdvanceDeductedTxtClosingAdvance一個GridView訪問設置.....使用KEYUP功能上TxtAdvanceDeducted我計算TxtClosingAdvance ...我的頁面顯示TxtClosingAdvance值文本框...但是,當我使用c#它給我的錯誤Input String was not in a correct format ...文本框的值使用javascript無法使用C#

當我通過Firebug的檢查,

<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事件javascript ...

回答

2

作爲猜測,您的字符串值爲空或包含不需要的符號,如果它包含400.00,請嘗試檢查((TextBox)row.Cells[6].FindControl("TxtClosingAdvance")).Text的值,因爲在服務器的區域設置「。」中導致錯誤。不是小數點符號。如果它爲空,這意味着ASP.NET不能識別您的JavaScript更改。出於安全原因,ASP.NET會從VIEWSTATE恢復不可編輯的控制值,請嘗試通過設置EnableViewState = false來禁用該控件的VIEWSTATE。

編輯

順便說有一個只讀文本框問題討論here

希望這有助於

+0

@Arsen的EnableViewState = 「假」 不工作.. – 2010-02-26 06:18:55

+0

是你的文本框只讀?你讀過一個問題嗎? – 2010-02-26 06:21:00

+0

@Arsen它已被討論在一個頁面中的文本框...但我的文本框是在一個GridView中...我如何添加只讀屬性...我應該使用rowdatabound事件... – 2010-02-26 06:21:48

相關問題