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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:19:32+00:00 2026-05-22T18:19:32+00:00

I have a grid on my page and using check box for checking one

  • 0

I have a grid on my page and using check box for checking one or more than one row in grid and i want to delete checked row from grid on the click of delete button which is out side the grid..

In table i have only name field there is no field like ID.

How can i delete record.

Thanks in advance..

Here is my code What i am doing:-

private void GetData()
{

    ArrayList arr;
    if (ViewState["TotalRecords"] != null)
    {
        arr = (ArrayList)ViewState["TotalRecords"];
    }
    else
    {
        arr = new ArrayList();
    }
    for (int i = 0; i < grdlistWord.Rows.Count; i++)
    {

        CheckBox chk = (CheckBox)grdlistWord.Rows[i].Cells[1].FindControl("chkWord");
        if (chk.Checked)
        {
            if (!arr.Contains(grdlistWord.Rows[i].Cells[1]))
            {
                arr.Add(grdlistWord.Rows[i].Cells[1]);
            }
        }
        else
        {
            if (arr.Contains(grdlistWord.Rows[i].Cells[1]))
            {
                arr.Remove(grdlistWord.Rows[i].Cells[1]);
            }
        }

    }
    ViewState["TotalRecords"] = arr;
}

protected void lnkbtnDelete_Click(object sender, EventArgs e)
{

    try
    {
        int count = 0;

        ArrayList arr = (ArrayList)ViewState["TotalRecords"];
        count = arr.Count;
        for (int i = 0; i < grdlistWord.Rows.Count; i++)
        {
            if (arr.Contains(grdlistWord.Rows[i].Cells[1].Text))
            {
                Response.Write(grdlistWord.Rows[i].Cells[1].Text.ToString());
                DeleteRecord(grdlistWord.Rows[i].Cells[1].Text.ToString());
                arr.Remove(grdlistWord.Rows[i].Cells[1].Text);
            }
        }
        ViewState["TotalRecords"] = arr;
        GridBind();

    }
    catch (SqlException ex)
    {
        ex.ToString();
    }

}


private void DeleteRecord(string word)
{

    string query = "delete from searchword where word=@word";

    SqlCommand cmd = new SqlCommand(query, con);
    cmd.Parameters.AddWithValue("@word", word);
    con.Open();
    cmd.ExecuteNonQuery();
    con.Close();
}

gridview html detail:

 <fieldset>
        <legend>List</legend>
        <asp:GridView ID="grdlistWord" runat="server" DataKeyNames="word" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" OnRowDataBound="grdlistWord_RowDataBound" OnRowDeleting="grdlistWord_RowDeleting">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:CheckBox ID="chkWord" runat="server" onclick="check_click(this);" />

                    </ItemTemplate>
                    <HeaderTemplate>
                        <asp:CheckBox ID="chkAll" runat="server" onclick="checkAll(this);" />
                        <asp:LinkButton ID="ButtonDelete" runat="server" Text="Delete" OnClick="ButtonDelete_Click"></asp:LinkButton>
                    </HeaderTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Word" HeaderText="Word" />
                <asp:HyperLinkField HeaderText="Edit" Text="edit" DataNavigateUrlFields="Word" DataNavigateUrlFormatString="SearchWord.aspx?words={0}&amp;mode=Edit" />
                <asp:CommandField ShowDeleteButton="True" HeaderText="Delete" />
            </Columns>
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <EditRowStyle BackColor="#999999" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <EmptyDataTemplate>Records not exist!</EmptyDataTemplate>
        </asp:GridView>

        <asp:HiddenField ID="hfCount" runat="server" Value = "0" />

    </fieldset>
  • 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-22T18:19:33+00:00Added an answer on May 22, 2026 at 6:19 pm
     protected void lnkbtnDelete_Click(object sender, EventArgs e)
            {
    
                int counter = 0;
                List<string> words = new List<string>();
                foreach (GridViewRow rowitem in grdlistWord.Rows)
                {
                    if (((CheckBox)rowitem.Cells[0].FindControl("chkWord")).Checked == true)//i consider that the check box is in the first column index ---> 0
                    {
                        counter++;
                        words.Add(rowitem.Cells[1].Text); //i consider that the word is in the second column index ---> 1
                    }
                }
                /////////////////////////////////////////////////////////////
                if(counter == 0) //no checks
                {
    
                 //show some message box to clarify that no row has been selected.
    
                }
                /////////////////////////////////////////////////////////////
                if (counter == 1) //one check
                {
    
                    DeleteRecord(words[0]);
                    //Show some message box to clarify that the operation has been executed successfully.
    
                }
                /////////////////////////////////////////////////////////////
                if (counter > 1) //more than one check
                {
                    for(int i=0; i<words.Count;i++)
                       {
                         DeleteRecord(words[i]);
                       }
                       //Show some message box to clarify that the operation has been executed successfully.
                }
    
                grdlistWord.DataBind();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the Blueprint CSS grid for my HTML page. I have a table
I have a grid that has multiple rows. I want to hide/show one of
Hopefully this is a quick one! I have an editable grid using 'clientSide' (local)
I have the following page layout using the 960 grid systm ---------------- header -----------------
I have a Grid Panel, which when I leave the page, I want a
I have an ExtJS grid on a web page and I'd like to save
I have a page with .Net grid view with about 12 text fields per
I have a page where search resuts are shown both in a grid and
I currently have a product view page that contains an MVCContrib HTML Grid with
I am using vb.net code. I have grid view, please see the code below:

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.