Click here to Skip to main content
16,019,435 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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:
VB
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:
VB
Dim _displayControl As Control = _gridView.Rows(_rowIndex).Cells(_columnIndex).Controls(1)


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. :)
Posted
Updated 5-Jan-12 13:12pm
v5

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 :
SQL
SELECT EMPNO, ENAME, SAL FROM EMP

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
 
Share this answer
 
v2
Comments
Ariel Riyo 8-Jan-12 19:13pm    
Thank you sir for helping just spotted the error. its the categoryBind before the execution. thank you for your help. more power. :)
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900