checbox in gridview on vb.net

Hi Expert,

I like if checkbox check, I need remove a row. Code have a error  'If chkRow.Checked Then' said chkRow need check is null, how i can do it?


 For Each row As GridViewRow In gdView.Rows

                If row.RowType = DataControlRowType.DataRow Then

                    Dim chkRow As CheckBox = TryCast(row.Cells(0).FindControl("chkRemove"), CheckBox)

                    If chkRow.Checked Then

                       Dim hfStudentNumber As HiddenField = DirectCast(row.FindControl("hfStudentNumber"), HiddenField)
                     'remove row hfStudentNumber

Thanks.
LVL 1
dshi15Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rajeeshmcaCommented:
Hi,

As per my understanding, your requirement is to delete multiple roes that are checked in checkbox.

Please find below link which is same as your requirement
http://www.codecomplete4u.com/delete-multiple-rows-gridview-using-checkbox-asp-net/

If you can post your entire code, I can find the issue with your project.

Regards
Rajeesh
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodeCruiserCommented:
Is the checkbox definitely in first column?

You can change this

  If chkRow.Checked Then

                       Dim hfStudentNumber As HiddenField = DirectCast(row.FindControl("hfStudentNumber"), HiddenField)
                     'remove row hfStudentNumber

to


If Not IsNothing(chkRow) Then
  If chkRow.Checked Then

                       Dim hfStudentNumber As HiddenField = DirectCast(row.FindControl("hfStudentNumber"), HiddenField)
                     'remove row hfStudentNumber
End If
End If


to get rid of the error.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Applications

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.