在Gridview中编辑一行的错误,该行在asp.net中被分页 [英] Error while editing a row in Gridview for which Paging is enbled in asp.net

查看:100
本文介绍了在Gridview中编辑一行的错误,该行在asp.net中被分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在我的asp.net Web应用程序Web表单中,我使用gridview来显示由客户/供应商完成的交易的列表. gridview已启用分页,页面大小为20,表示那里有26个事务,因此gridview包含26行.

问题是,当我尝试编辑除第一行以外的其他行时,系统会抛出异常,即:

Hi all,

In my asp.net web applications web form i used gridview to display list of transactions done by customer/vendors. The gridview is paging enabled, page size is 20,present there is 26 transactions are there so gridview contains 26 rows.

The problem is when ever i am trying to edit row which are present other then first page an exception is throwing by system that is:

Exception Details: System.ArgumentOutOfRangeException: Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index



Gridview行数据绑定的代码如下:



Gridview rowdatabound code is as follows:

protected void gvTransactionDetails_RowCommand(object sender, GridViewCommandEventArgs e)
 {
   if (e.CommandName == "Edit")
   {

    int igvTransactionDetailsIndex = Convert.ToInt32(e.CommandArgument);


   GridViewRow gvTransactionDetailsrow = gvTransactionDetails.Rows[igvTransactionDetailsIndex];
   Session["TDID"] = gvTransactionDetails.DataKeys[igvTransactionDetailsIndex].Value;
         
    Response.Redirect("~/AddEditTransactionDetails.aspx?AddEdit=Edit&CusVen=" +sCusVen);
           }
       }




请任何人帮助我解决该错误.

在此先感谢
Uday




please anybody help me to solve that error.

Thanks in advance
Uday

推荐答案

首先,在不显示抛出/传播行的确切行的情况下问这样的问题是不好的.您可以在调试器下运行代码,也可以通过在该线程的堆栈顶部捕获所有异常并检查Exception.Stack来发现它.

最有可能的是,这是第一次将igvTransactionDetailsIndex用作索引的行,或在下一行. If可以小于0或大于或等于Rows的数目或DataKeys的数目.检查此变量的值.

—SA
First, this is not nice to ask such question without showing exact line where it was thrown/propagated. You can find it out running the code under debugger or by catching all exception on top of the stack of this thread and examining Exception.Stack.

Most likely, this is the line where igvTransactionDetailsIndex is first used as an index, or in next line. If could be less than 0 or more or equal to the number of Rows or number of DataKeys. Check up the value of this variable.

—SA


请放置您的gridview html代码,以便清除有关命令参数和datakeys参数的图片,这将有助于根据您的需要找到解决方案代码,我认为您需要检查igvTransactionDetailsIndex的值,理想情况下,它应该接受行索引,肯定会有解决方案,但是您需要为此添加gridview html代码.
please put your gridview html code so that it will clear some picture regarding command argument and datakeys parameter which will help to find out the solution as per you code i think you need to check the value of igvTransactionDetailsIndex ideally it should accept row index surely there will a solution but you need to put your gridview html code for this.


这篇关于在Gridview中编辑一行的错误,该行在asp.net中被分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆