Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How i get eval command event from gridview inside datalist on save button click in vb.net My code is below problem occuring at this line



**> Dim AccountsGrid As GridView =
> CType(e.Item.FindControl("AccountsGrid"), GridView)**

What I have tried:

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim constr As String = ConfigurationManager.ConnectionStrings("WGFOLTP").ConnectionString
        Dim con As New SqlConnection(constr)
        Dim cmd As New SqlCommand()
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "sp_permissionupdate"
        cmd.Connection = con
        con.Open()
        Dim AccountsGrid As GridView = CType(e.Item.FindControl("AccountsGrid"), GridView)
        For Each row2 As GridViewRow In AccountsGrid.Rows
            'Dim id As Integer = Convert.ToInt32(AccountsGrid.DataKeys(row2.RowIndex).Values(0))
            Dim lbl As Label = DirectCast(row2.FindControl("permissionid"), Label)
            Dim check As Boolean = TryCast(row2.FindControl("checkviews"), CheckBox).Checked
            Dim view As Boolean = TryCast(row2.FindControl("ischeck"), CheckBox).Checked
            Dim maker As Boolean = TryCast(row2.FindControl("ismarked"), CheckBox).Checked
            cmd.Parameters.Clear()
            'cmd.Parameters.AddWithValue("@id", id)
            cmd.Parameters.AddWithValue("@roleid", rolesDropDownList.SelectedValue)
            cmd.Parameters.AddWithValue("@permissionid", lbl)
            cmd.Parameters.AddWithValue("@Ismaker", maker)
            cmd.Parameters.AddWithValue("@Ischeck", check)
            cmd.Parameters.AddWithValue("@ViewOnly", view)

            cmd.ExecuteNonQuery()
            con.Close()

            labelpop.Text = "Data is Updated"
        Next

    End Sub
Posted
Updated 20-Apr-17 18:38pm
Comments
Ralf Meier 20-Apr-17 2:22am    
Where (exactly) do you get an error ?
And what Kind of error ?
Member 12439303 21-Apr-17 2:00am    
Dim AccountsGrid As GridView = CType(e.Item.FindControl("AccountsGrid"), GridView)



error at e.item.findcontrol


eror is showing below


Unable to cast object of type 'System.EventArgs' to type 'System.Web.UI.WebControls.CommandEventArgs'.


i already changed the

EventArgs

to

DataListItemEventArgs

but not solved the issue

plz suggest me any other tutorial of vb for get the value of grdiveiw inside the dataliist
Ralf Meier 21-Apr-17 7:02am    
I'm very sorry ... but the EventsArgs from Button.Click doesn't have an Item - so how should FindControl could work ?
To whom belongs the GridView "AccountsGrid" ? Where have you placed it ?
FindControl could only work with the Controls-Collection of the Parent (perhaps a Form) where the GridView is placed on ...

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