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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:57:30+00:00 2026-06-04T15:57:30+00:00

I have a radiobutton, a gridview and a button on my form. Here is

  • 0

I have a radiobutton, a gridview and a button on my form. Here is my datagridview selection_changed code sample:

private void DataGridView1_SelectionChanged(object sender, EventArgs e)
{
    if (rdb_Delete.Checked)
    {
        lbl_deleteMsg.Text = DataGridView1.SelectedRows.Count.ToString() 
                + " rows selected.";
    }
 }

I want to delete selected rows from database and refresh the datagridview when user pushes the delete button.
I have an Id column in my database but I don’t show it to the user on datagridview.

So by sql query how can I delete the selected row from my database? Here is my delete button clicked code but it doesn’t seems to work (because of selection changed event):

private void btn_Delete_Click(object sender, EventArgs e) 
{       
    if (rdb_Delete.Checked)
    {
        int count = DataGridView1.SelectedRows.Count;
        int length = DataGridView1.RowCount;
        if (!count.Equals(0))
        {
            if (confirm())
            {
                for (int i = 0; i < length; i++)
                {
                    if (DataGridView1.Rows[i].Selected)
                    {
                        //DataGridView1.SelectedRows[i].Selected = false;
                        DataGridView1.Rows.RemoveAt(i);
                        i--;
                    }
                }
            }
        }
    }
}

Edit : I also find a small answer maybe helps someone in such a case. DataGridView’s any column can be visible = false so it’ll be accessible by code such as :

int rowID = int.Parse(DataGridView1[0, selectedIndex].Value.ToString());
  • 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-06-04T15:57:31+00:00Added an answer on June 4, 2026 at 3:57 pm

    Try this:

    private void btn_Delete_Click(object sender, EventArgs e) 
    {       
        if (rdb_Delete.Checked)
        {
            foreach (DataGridViewRow row in DataGridView1.SelectedRows)
            {
                //delete record and then remove from grid. 
                // you can use your own query but not necessary to use rowid
                int selectedIndex = row.Index;         
    
                // gets the RowID from the first column in the grid
                int rowID = int.Parse(DataGridView1[0, selectedIndex].Value.ToString());
                string sql = "DELETE FROM Table1 WHERE RowID = @RowID";
    
                // your code for deleting it from the database
                // then your code for refreshing the DataGridView
    
                DataGridView1.Rows.Remove(row);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here i have gridview which contain some values retrieved from database.We put radiobutton list
I have a radiobutton column in a gridview, inside many nested asp tables. I
I have a gridview inside an updatepanel. It has a TemplateField column with radiobutton:
In Silverlight 2.... I have a RadioButton in my xaml code as follows: <RadioButton
I have asp.net code: <asp:RadioButton ID=RadioButton1 CssClass=rb1 GroupName=grp1 runat=server /> <br/> <asp:RadioButton ID=RadioButton2 CssClass=rb2
I have the following radio button bound to the variable IsAllowed <RadioButton Name=YesRadioButton Margin=5,5,0,0
I have 4 jquery radio buttons in my form something like this <form:radiobutton path=lcmoption
I have an html form with: <input name=gender dojoType=dijit.form.RadioButton id=male checked=checked>male <input name=gender dojoType=dijit.form.RadioButton
I want to create a custom drawable for RadioButton's button drawable. I have created
I have designed a gridview with a radio button inside the itemtemplet. I also

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.