Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6828621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:24:17+00:00 2026-05-26T22:24:17+00:00

I am following on a tutorial from here . But I got jammed at

  • 0

I am following on a tutorial from here.

But I got jammed at the part where I need to grep the primary key of the checked rows.

Below is my current code:

protected void DeleteChecked_Click(object sender, EventArgs e)
{
    bool atLeastOneRowDeleted = false;

    foreach (GridViewRow row in GridView1.Rows)
    {

        CheckBox cb = (CheckBox)row.FindControl("UserSelector");
        if (cb != null && cb.Checked)
        {

            atLeastOneRowDeleted = true;

            int employeeID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);

            SqlDataSource1.SelectCommand = "DELETE FROM [UserDB] where Employee like " +employeeID;
            SqlDataSource1.DataBind();
        }
    }
}

I do not know what I should change and how do I grep my ‘Employee’ variable on my GridView so that I can insert it into my DELETE statement.

Below is my sample GridView and the error I am meeting now.


enter image description here

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:24:17+00:00Added an answer on May 26, 2026 at 10:24 pm

    Set a breakpoint on that line and look at the value of GridView1.DataKeys. I bet there are no keys in that array, so DataKeys[0] will throw that exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am following the tutorial here: http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-1 But I'm having trouble with Part 4:
I'm following the tutorial from Ryan B, but I got something wrong when trying
I am trying to implement remote validation by following tutorial from Here but it
I'm following the kernel tutorial from here im having problems compiling my files. i
I am using following a tutorial from here: http://www.shopdev.co.uk/blog/cookies-with-jquery-designing-collapsible-layouts/ This is the script I
ok, im following the RW tutorial on box2d, i have got to the part
I need help with my jcrop preview. I am following this tutorial from railscasts
I am following a tutorial from nettuts, specifically here: http://blog.themeforest.net/tutorials/jquery-for-absolute-beginners-day-11/ I am 3/4's of
So here I am,got some help from some web tutorials and performing following Asynchronous
I managed to get authentication to work by following the tutorial from this page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.