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 6815507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:48:57+00:00 2026-05-26T20:48:57+00:00

I have a GirdView table in my application. I have a Delete link button

  • 0

I have a GirdView table in my application. I have a Delete link button and a checkbox in my first column. Below are snapshots:

enter image description hereenter image description here

I can manually delete each row by clicking Delete link button on each row.

However, I would want to enable the checkbox to delete multiple rows.

Below is my code for my Delete link button:

LinkButton lnk = (LinkButton)sender; 
        string stid = lnk.CommandArgument.ToString();
        SqlConnection conn = new SqlConnection("Data Source=DATASOURCE");
        string sql = string.Format("DELETE FROM [UserDB] where Employee like '%{0}%'",stid);
        SqlCommand cmd = new SqlCommand(sql,conn);
        conn.Open();
        cmd.ExecuteNonQuery();

Below is my code for the current Delete Checked button:

bool atLeastOneRowDeleted = false;
        foreach (GridViewRow row in GridView1.Rows)
        {
            // Access the CheckBox
            CheckBox cb = (CheckBox)row.FindControl("UserSelection");
            if (cb != null && cb.Checked)
            {
                atLeastOneRowDeleted = true;
                // How do I get the value from my Employee column?
                string userID = ???;


           SqlConnection conn = new SqlConnection("Data Source=DATASOURCE");
           string sql = string.Format("DELETE FROM [UserDB] where Employee like '%{0}%'",userID);
           SqlCommand cmd = new SqlCommand(sql,conn);
           conn.Open();
           cmd.ExecuteNonQuery();
            }
        }

I would like to know how should I grep userID, which is Employee key in the GridView, to INSERT it into my SQL delete statement?

  • 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-26T20:48:58+00:00Added an answer on May 26, 2026 at 8:48 pm

    I think you want

    bool atLeastOneRowDeleted = false;
        foreach (GridViewRow row in GridView1.Rows)
        {
            // Access the CheckBox
            CheckBox cb = (CheckBox)row.FindControl("UserSelection");
            if (cb != null && cb.Checked)
            {
                atLeastOneRowDeleted = true;
                //assuming you have the ID column after the controls
                string CusId = (row.Cells[3].Text);
    
    
           SqlConnection conn = new SqlConnection("Data Source=DATASOURCE");
           string sql = string.Format("DELETE FROM [UserDB] where Employee like '%{0}%'",userID);
           SqlCommand cmd = new SqlCommand(sql,conn);
           conn.Open();
           cmd.ExecuteNonQuery();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a gridview that renders as a table. I have an Add button
I have GridView which I can select a row. I then have a button
I have an asp.net application in which I am inserting into an sql table
In my .NET application I need to add a checkbox to each row in
Hey i have a simple ASP.NET application Table with this schema: id | Owner
I have a gridview table that has three columns..fileID, uploadedBy and delete. Only the
I have a DataGridView in my application with values from a database table. I
I can update some tables just fine, but a certain table I have cannot
in web application, i have a gridview in that each row contain 3 textboxes
I have two Gridview in my Web application.I need ,while clicking the (ExcelExpot) button

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.