Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a "Compilation Error" in Gridview control. Below is my code.
gv is gridview control. pls help Me.

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: BC30455: Argument not specified for parameter 'index' of 'Public ReadOnly Default Property Item(index As Integer) As System.Web.UI.WebControls.GridViewRow'.

Source Error:
Line 18: 'Dim myGridItem As DataGridItem
Line 19: Dim myGridItem As New GridView
Line 20: For Each myGridItem In gv.Rows.Item
Line 21: If CType(myGridItem.Cells(0).Controls(0), CheckBox).Checked = True Then
Line 22: cmd.Parameters.AddWithValue("@UserName", Me.txtUserName.Text)


Here is code

C#
Try
   Dim cmd As New SqlCommand("usp_UserRight_Insert", conn)
   cmd.CommandType = CommandType.StoredProcedure
   'Dim myGridItem As DataGridItem
   Dim myGridItem As New GridView
     For Each myGridItem In gv.Rows.Item
        If CType(myGridItem.Cells(0).Controls(0), CheckBox).Checked = True Then
           cmd.Parameters.AddWithValue("@MenuName", Me.gv.SelectedRow.Cells(1).Text)
           cmd.Parameters.AddWithValue("@MenuLink", Me.gv.SelectedRow.Cells(2).Text)
           Dim da As New SqlDataAdapter(cmd)
           Dim dt As New DataTable
           da.Fill(dt)
         End If
     Next
Catch ex As Exception
      MsgBox("Error:" & vbCrLf & ex.Message)
Finally
      conn.Close()
End Try


Pls Help me

thanks
Maideen
Posted
Updated 6-Jul-19 16:02pm
v2

If CType(myGridItem.Cells(0).Controls(0), CheckBox).Checked

should be
If CType(myGridItem.rows(0).FindControl("Controlname"), CheckBox).Checked
 
Share this answer
 
Comments
Member 14188766 6-Jul-19 2:09am    
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.
SQL
For i = 0 To GridView1.Rows.Count - 1
    If DirectCast(GridView1.Rows(i).FindControl("chk"), CheckBox).Checked() Then
        Dim row As GridViewRow = GridView1.Rows(i)
        cmd = New SqlCommand
        cmd.Connection = conn
        cmd.CommandText = "INSERT INTO Z_User_MenuVSGroup(menu_id, menu_name, menu_parent_id, menu_url, group_code) Values(@menuid,@menuname,@menuparentid,@menuurl,@groupcode)"
        cmd.CommandType = CommandType.Text
        conn.Open()
        Try
            cmd.Parameters.AddWithValue("@menuid", row.Cells(1).Text)
            cmd.Parameters.AddWithValue("@menuname", row.Cells(2).Text)
            cmd.Parameters.AddWithValue("@menuparentid", row.Cells(4).Text)
            cmd.Parameters.AddWithValue("@menuurl", row.Cells(5).Text)
            cmd.Parameters.AddWithValue("@groupcode", UCase(Me.cboDesigCode.SelectedValue))

            cmd.ExecuteNonQuery()
        Catch ex As Exception

        Finally
            cmd = Nothing
            conn.Close()

        End Try

    End If
Next
 
Share this answer
 
Comments
CHill60 7-Jul-19 9:59am    
It took you 7 years to find a solution? :-O

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