System.ArgumentOutOfRangeException

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default System.ArgumentOutOfRangeException

    Specified argument was out of the range of valid values. Parameter name:
    index
    Exception Details: System.ArgumentOutOfRangeException: Specified argument
    was out of the range of valid values. Parameter name: index
    Below is my code:

    Sub MyDataGrid_EditCommand(s As Object, e As DataGridCommandEventArgs )
    MyDataGrid.EditItemIndex = e.Item.ItemIndex
    BindData
    End Sub
    Sub MyDataGrid_Cancel(Source As Object, E As DataGridCommandEventArgs)
    MyDataGrid.EditItemIndex = -1
    BindData()
    End Sub

    Sub MyDataGrid_UpdateCommand(s As Object, e As DataGridCommandEventArgs )
    Dim conn As SqlConnection
    Dim MyCommand As SqlCommand
    Dim strConn as string =
    "server=localhost;trusted_connection=true;database =PTG"
    Dim txtDate As textbox = E.Item.cells(2).Controls(0)
    Dim txtMorning As textbox = E.Item.cells(3).Controls(0)
    Dim txtAfternoon As textbox = E.Item.cells(4).Controls(0)
    Dim txtNight As textbox = E.Item.cells(5).Controls(0)
    Dim txtMin As textbox = E.Item.cells(6).Controls(0)
    Dim txtMax As textbox = E.Item.cells(7).Controls(0)
    Dim strUpdateStmt As String

    strUpdateStmt =" UPDATE Weather SET" & _
    " Date =@Date, morning =@morning, afternoon =@afternoon, night
    =@night, min =@min, max =@max" & _
    " WHERE wea_id = @wea_id "
    conn = New SqlConnection(strConn)
    MyCommand = New SqlCommand(strUpdateStmt, conn)
    MyCommand.Parameters.Add(New SQLParameter("@Date", txtDate.text))
    MyCommand.Parameters.Add(New SQLParameter("@morning",
    txtMorning.text))
    MyCommand.Parameters.Add(New SQLParameter("@afternoon",
    txtAfternoon.text))
    MyCommand.Parameters.Add(New SQLParameter("@night", txtNight.text))
    MyCommand.Parameters.Add(New SQLParameter("@min", txtMin.text))
    MyCommand.Parameters.Add(New SQLParameter("@max", txtMax.text))
    MyCommand.Parameters.Add(New SQLParameter("@wea_id",
    e.Item.Cells(1).Text ))
    conn.Open()
    MyCommand.ExecuteNonQuery()
    MyDataGrid.EditItemIndex = -1
    conn.close
    BindData
    End Sub

    Sub Page_Load(Source as Object, E as EventArgs)
    if not Page.IsPostBack then
    BindData
    end if
    End Sub
    Sub BindData()
    Dim strConn as string =
    "server=localhost;trusted_connection=true;database =PTG"
    Dim sql as string = "Select wea_id, Date, morning, afternoon, night, min,
    max from Weather"
    Dim conn as New SQLConnection(strConn)
    Dim objDR as SQLDataReader
    Dim Cmd as New SQLCommand(sql, conn)
    conn.Open()
    objDR=Cmd.ExecuteReader(system.data.CommandBehavio r.CloseConnection)
    MyDataGrid.DataSource = objDR
    MyDataGrid.DataBind()
    conn.close
    End Sub

    Thanks in advance.


    leezard Guest

  2. Similar Questions and Discussions

    1. Some 'System Calls' was Capturing system call output value
      On Friday, Nov 14, 2003, at 18:39 US/Pacific, Jerry Rocteur wrote: Wiggins is the one who deserves the point, since he was the one with the...
    2. System.Net.WebException occurred in system.web.services.dll - HTTP status 405: Method not allowed.
      Hi, Have anyone ever encountered an exception error: The request failed with HTTP status 405: Method not allowed when trying to remotely invoke a...
    3. The type System.Web.UI.WebControls.TextBox in Assembly System.Web...error
      I've been getting this error every since I installed InstallSqlState to handle my viewState Sessions. it only happens on 1 section of my asp.net...
    4. Method not found: System.Collections.Specialized.NameValueCollection System.Web.HttpRequest.get_QueryString().
      I just recently started getting the above error on a page I am posting MULTIPART/FORM-DATA. We have SoftArtisans FileUp component and Filter...
    5. How to: Network XP system to system running 2000?
      I have a desktop running XP. I have a laptop running 2000. They share an internet connection through a Linksys wireless router. My question...
  3. #2

    Default Re: System.ArgumentOutOfRangeException

    I've figured it out.
    thanks for viewing. :)

    "leezard" <[email protected]> wrote in message
    news:ODEgu%[email protected]..
    > Specified argument was out of the range of valid values. Parameter name:
    > index
    > Exception Details: System.ArgumentOutOfRangeException: Specified argument
    > was out of the range of valid values. Parameter name: index
    > Below is my code:
    >
    > Sub MyDataGrid_EditCommand(s As Object, e As DataGridCommandEventArgs )
    > MyDataGrid.EditItemIndex = e.Item.ItemIndex
    > BindData
    > End Sub
    > Sub MyDataGrid_Cancel(Source As Object, E As DataGridCommandEventArgs)
    > MyDataGrid.EditItemIndex = -1
    > BindData()
    > End Sub
    >
    > Sub MyDataGrid_UpdateCommand(s As Object, e As DataGridCommandEventArgs )
    > Dim conn As SqlConnection
    > Dim MyCommand As SqlCommand
    > Dim strConn as string =
    > "server=localhost;trusted_connection=true;database =PTG"
    > Dim txtDate As textbox = E.Item.cells(2).Controls(0)
    > Dim txtMorning As textbox = E.Item.cells(3).Controls(0)
    > Dim txtAfternoon As textbox = E.Item.cells(4).Controls(0)
    > Dim txtNight As textbox = E.Item.cells(5).Controls(0)
    > Dim txtMin As textbox = E.Item.cells(6).Controls(0)
    > Dim txtMax As textbox = E.Item.cells(7).Controls(0)
    > Dim strUpdateStmt As String
    >
    > strUpdateStmt =" UPDATE Weather SET" & _
    > " Date =@Date, morning =@morning, afternoon =@afternoon, night
    > =@night, min =@min, max =@max" & _
    > " WHERE wea_id = @wea_id "
    > conn = New SqlConnection(strConn)
    > MyCommand = New SqlCommand(strUpdateStmt, conn)
    > MyCommand.Parameters.Add(New SQLParameter("@Date", txtDate.text))
    > MyCommand.Parameters.Add(New SQLParameter("@morning",
    > txtMorning.text))
    > MyCommand.Parameters.Add(New SQLParameter("@afternoon",
    > txtAfternoon.text))
    > MyCommand.Parameters.Add(New SQLParameter("@night",
    txtNight.text))
    > MyCommand.Parameters.Add(New SQLParameter("@min", txtMin.text))
    > MyCommand.Parameters.Add(New SQLParameter("@max", txtMax.text))
    > MyCommand.Parameters.Add(New SQLParameter("@wea_id",
    > e.Item.Cells(1).Text ))
    > conn.Open()
    > MyCommand.ExecuteNonQuery()
    > MyDataGrid.EditItemIndex = -1
    > conn.close
    > BindData
    > End Sub
    >
    > Sub Page_Load(Source as Object, E as EventArgs)
    > if not Page.IsPostBack then
    > BindData
    > end if
    > End Sub
    > Sub BindData()
    > Dim strConn as string =
    > "server=localhost;trusted_connection=true;database =PTG"
    > Dim sql as string = "Select wea_id, Date, morning, afternoon, night, min,
    > max from Weather"
    > Dim conn as New SQLConnection(strConn)
    > Dim objDR as SQLDataReader
    > Dim Cmd as New SQLCommand(sql, conn)
    > conn.Open()
    > objDR=Cmd.ExecuteReader(system.data.CommandBehavio r.CloseConnection)
    > MyDataGrid.DataSource = objDR
    > MyDataGrid.DataBind()
    > conn.close
    > End Sub
    >
    > Thanks in advance.
    >
    >

    leezard Guest

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139