索引超出范围-找不到真正的问题 [英] Index out of range - can't find the real problem

查看:141
本文介绍了索引超出范围-找不到真正的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.在这里,我们需要专业的帮助来解决问题.

我们正在努力在Gridview中拥有一个可编辑的单元格,我们的第一个问题是进入RowCommand,但是我们已经在RowCommand内部解决了它,这里是代码:

Hey guys. We need a professional help with our problem here.

We are working to have a editable cell in a Gridview our first problem was getting inside the RowCommand but we already solved it inside the RowCommand here is the code:

Protected Sub grdCourse_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdCourse.RowCommand

        Dim _gridView As GridView = DirectCast(sender, GridView)
        
        Select Case e.CommandName
            Case ("SingleClick")
                             Dim _rowIndex As Integer = Integer.Parse              (e.CommandArgument.ToString())
                                Dim _columnIndex As Integer = Integer.Parse(Request.Form("__EVENTARGUMENT"))
                            _gridView.SelectedIndex = _rowIndex
                              _gridView.DataBind()

                              Dim _displayControl As Control = _gridView.Rows(_rowIndex).Cells(_columnIndex).Controls(1)
                _displayControl.Visible = False
                             Dim _editControl As Control = _gridView.Rows(_rowIndex).Cells(_columnIndex).Controls(3)
                _editControl.Visible = True
             event
                _gridView.Rows(_rowIndex).Cells(_columnIndex).Attributes.Clear()
                             ScriptManager.RegisterStartupScript(Me, [GetType](), "SetFocus", "document.getElementById('" + _editControl.ClientID + "').focus();", True)
                             If TypeOf _editControl Is DropDownList AndAlso TypeOf _displayControl Is Label Then
                    DirectCast(_editControl, DropDownList).SelectedValue = DirectCast(_displayControl, Label).Text
                End If
                         If TypeOf _editControl Is TextBox Then
                    DirectCast(_editControl, TextBox).Attributes.Add("onfocus", "this.select()")
                End If
                Exit Select
        End Select

 End Sub



但是这一行有一个错误:



But there is a error in this line:

Dim _displayControl As Control = _gridView.Rows(_rowIndex).Cells(_columnIndex).Controls(1)



它说该索引超出范围,但是当我通过设置一个断点来检查_rowIndex _columnIndex 的值时,该值是正确的,现在我真的搞砸了我该怎么办,并思考导致它的原因.
请帮我解决我的问题.

预先感谢我期待您的建议和解答.

非常感谢程序员. :)



It said the index was out of range but when I check the value of _rowIndex and _columnIndex by putting a breakpoint the value was correct now im really messed up thinking what should i do and thinking what causes it.

Please help me with my problem.

thanks in advance im looking forward for your suggestion and answers.

Thank you very much Programmers. :)

推荐答案

如果在调试器中运行此行,您将能够看到真正的问题.仅检查_rowIndex_columnIndex是不够的.当您使用Controls(1)时,您假定至少有2个控件.即Controls.Count > 1.为什么?请记住,索引是从零开始的.在运行此行之前,您需要使用Controls(0)或检查所有三个索引(无论如何都很好).

请在询问类似问题之前始终使用Debugger,以节省您的时间和我们的时间.

-SA
You will be able to see the real problem if you run this line under debugger. Checking up _rowIndex and _columnIndex is not enough. When you use Controls(1), you assume that there are at least 2 controls; that is, Controls.Count > 1. Why? Remember indices are zero-based. You either need to use Controls(0) or check up all three indices before running this line (good to do anyway).

Please, always use Debugger before asking questions like that, save your time and our time.

—SA


SQL语句是此IndexOutOfRange错误的主要问题

请检查您的SQL Querry,仅当您尝试检索SQL Querry中未提及的列时,才会引发IndexOutOfRange错误.
示例:
SQL Statement is the main problem for this IndexOutOfRange Error

Pls Check your sql querry, The IndexOutOfRange Error raises only when if you are trying to retrieve the column which is not mentioned in the sql querry.
Example :
SELECT EMPNO, ENAME, SAL FROM EMP


上面是您的sql语句,您正尝试从数据表中存在的列中检索数据,但HIREDATE,MGR等sql语句中没有该列.

我希望本文能解决您的问题


The above is your sql statement and you are trying retrieve the data from the column which is present in your data table but not in your sql statement such HIREDATE, MGR etc.

i hope this article will solve your issue


这篇关于索引超出范围-找不到真正的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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