integer超出范围_如何解决索引超出范围的异常?

Compilation Error:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.Compiler Error Message: CS0266: Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?)

Source Error:

Line 270:

Line 271:

Line 272: n_sno = Convert.ToInt64(((TextBox)(row.Cells[1].Controls[0])).Text);

Line 273: n_date = ((TextBox)(row.Cells[2].Controls[1])).Text.Trim();

Line 274: n_c_ref = ((TextBox)(row.Cells[3].Controls[2])).Text.Trim();

Source File: c:\Users\bhushan.COMTEK\Desktop\Halo Convert in Publication\PublicationWeb\Indent.aspx.cs Line: 272

plz check this code.......

firstly i''m taking old values then new values then new value inserted in gridvalue but when i''m taking new serialnumber: show exception- Index out of range.

Error line is this : n_sno = Convert.ToInt16(((TextBox)(row.Cells[1].Controls[0])).Text);

protected void grid_indent_RowUpdating(object sender, GridViewUpdateEventArgs e)

{

try

{

//retrieve the table from the session object...

//DataTable dt = (DataTable)Session["grid_value"];

//update the values of grid...

List objList = (List)Session["listdata"];

GridViewRow row = grid_indent.Rows[e.RowIndex];

o_sno = objList[row.DataItemIndex].serialnumber;

o_date = objList[row.DataItemIndex].date;

o_c_ref = objList[row.DataItemIndex].coderef;

o_i_name = objList[row.DataItemIndex].item_name;

o_inhand = objList[row.DataItemIndex].inhand;

o_request = objList[row.DataItemIndex].newrequest;

o_rate = objList[row.DataItemIndex].rate;

o_amt = objList[row.DataItemIndex].amount;

n_sno = Convert.ToInt16(((TextBox)(row.Cells[1].Controls[0])).Text);

n_date = ((TextBox)(row.Cells[2].Controls[1])).Text.Trim();

n_c_ref = ((TextBox)(row.Cells[3].Controls[2])).Text.Trim();

n_i_name = ((TextBox)(row.Cells[4].Controls[3])).Text.Trim();

n_inhand = Convert.ToInt32(((TextBox)(row.Cells[5].Controls[4])).Text.Trim());

n_request = Convert.ToInt32(((TextBox)(row.Cells[6].Controls[5])).Text.Trim());

n_rate = ((TextBox)(row.Cells[7].Controls[6])).Text.Trim();

n_amt = ((TextBox)(row.Cells[8].Controls[7])).Text.Trim();

objList[row.DataItemIndex].serialnumber =n_sno;

objList[row.DataItemIndex].date = n_date;

objList[row.DataItemIndex].coderef = n_c_ref;

objList[row.DataItemIndex].item_name = n_i_name;

objList[row.DataItemIndex].inhand = n_inhand;

objList[row.DataItemIndex].newrequest = n_request;

objList[row.DataItemIndex].rate = n_rate;

objList[row.DataItemIndex].amount = n_amt;

grid_indent.EditIndex = -1;

popUpData();

}

catch (Exception ex)

{

Response.Write(ex.Message);

}

finally

{ }

}

thanks in advance...

Bhushan

解决方案Have a look at this article if you want to know about ways to deal with this sort of problem

Mastering Debugging in Visual Studio 2010 - A Beginner''s Guide[^]

Having reread your question actually - maybe all you needed was a pair of extra eyes :)

Looks like n_sno was defined to be an int, i.e. a 32 bit integer variable. Hence, you need a Convert.ToInt32().

As far as your IndexOutOfRangeException is concerned, check that the row has a Cell with index 1, and that that cell has a control with index 0.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值