本文介绍了代码工作但仍然出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我的代码正在对记录进行一些更新。它从网格获取ID更新。我正在将INT传递给我的方法来更新记录。我的代码正在工作,虽然我仍然得到''输入字符串格式不正确。'' 代码: foreach(GridViewRow grid.Rows) { CheckBox chk =(CheckBox)gr.FindControl(" checkbox"); if(chk) .Checked) { Data + = grid.DataKey [grid.RowIndex] .value +" ;;" ;; } } String [] rowValues = Data.Split('';''); foreach(rowValues中的字符串updateValues { Update.UpdateUserRow(Convert.ToInt32(updateValues)); } this正在更新在网格中选择的记录,但我收到错误 ''输入字符串的格式不正确。'' 任何想法为什么? 解决方案 String [] rowValues = Data.TrimEnd('';'')。Split('';''); - - Mark Rae ASP.NET MVP http://www.markrae.net 我假设您只想更新每一行一次?使用你的代码你将会更新第一行,然后当第二行更新时,你会再次更新第一行,依此类推。如果选择了十行,那么 将更新第一行十次。 只需获取值并更新行: foreach(grid.Rows中的GridViewRow行){ CheckBox chk =(CheckBox)gr.FindControl(" checkbox"); if(chk.Checked){ int value = int.Parse(grid.DataKey [grid.RowIndex] .value); Update.UpdateUserRow(value); } } - G?跑Andersson _____ http://www.guffa.com I have code that is doing some updating to a record. Its getting the ID to update from the Grid. I''m passing an INT to my method to update the record. My code is working though I''m still getting an ''input string was not in a correct format.''Code:foreach (GridViewRow row in grid.Rows){CheckBox chk = (CheckBox)gr.FindControl("checkbox");if (chk.Checked){Data+= grid.DataKey[grid.RowIndex].value + ";";}}String[] rowValues= Data.Split('';'');foreach (string updateValues in rowValues{Update.UpdateUserRow(Convert.ToInt32(updateValues) );}this is updating the record that is selected in the grid, but I''m getting the error''input string was not in a correct format.''any idea why? 解决方案String[] rowValues= Data.TrimEnd('';'').Split('';'');--Mark RaeASP.NET MVP http://www.markrae.netI assume that you only want to update each row once? With your code youwould update the first row, then your would update first row again whenthe second row is updated, and so on. If ten rows are selected, youwould be updating the first of them ten times.Just get the value and update the row:foreach (GridViewRow row in grid.Rows) {CheckBox chk = (CheckBox)gr.FindControl("checkbox");if (chk.Checked) {int value = int.Parse(grid.DataKey[grid.RowIndex].value);Update.UpdateUserRow(value);}}--G?ran Andersson_____ http://www.guffa.com 这篇关于代码工作但仍然出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-11 21:27