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

  • Home
  • SEARCH
  • 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 7701943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:06:51+00:00 2026-05-31T23:06:51+00:00

I want to keep some data which is checkhed in array list. I added

  • 0

I want to keep some data which is checkhed in array list. I added checkbox to gridview and when i checked one of items. click event of checkbox runs for all so for example, I have two data when i click the any checkbox it runs 4 times, so it works for each one however, I want that only the item of one checkbox which is checked or unchecked is added to list. Is there solution or another solution

     // checkbox click event 
    protected void SelectedFriends_Click(object sender, EventArgs e)
      {

        bool isflag=false;

        foreach (GridViewRow row in GridView1.Rows)
        {
            // Access the CheckBox
            CheckBox cb = (CheckBox)row.FindControl("FriendSelector");

            if (cb != null && cb.Checked)
            {




                string friendname = GridView1.Rows[row.RowIndex].Cells[1].Text.ToString();
                for (int i = 0; i < list.Count; i++)
                {
                    if (friendname.Equals(list[i].ToString()))
                    {
                        isflag = true;
                    }
                }
                // if it is added previously  don't add to list
                if(!isflag)
                {
                    list.Add(friendname);
                }

            }
            else
            {

                string friendname = GridView1.Rows[row.RowIndex].Cells[1].Text.ToString();
                for (int i = 0; i < list.Count; i++)
                {
                    if (friendname.Equals(list[i].ToString()))
                    {
                        isflag = true;
                    }
                }
                // if it is not checked and it is in list delete it from list
                if(isflag)
                {

                    list.Remove(friendname);
                }

            }
        }


    }






    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Font-Bold="True" 
            Width="157px">
            <Columns>
            <asp:TemplateField HeaderText="Select">
            <ItemTemplate>

                            <asp:CheckBox runat="server" id="FriendSelector" 
                  oncheckedchanged="SelectedFriends_Click" AutoPostBack="True">

            </asp:CheckBox>

            </ItemTemplate>

            </asp:TemplateField>
                <asp:BoundField DataField="F_Name" HeaderText="Friend Name" 
                    SortExpression="F_Name" />
            </Columns>


        </asp:GridView>
  • 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-31T23:06:51+00:00Added an answer on May 31, 2026 at 11:06 pm

    Can you try this?

    protected void SelectedFriends_Click(object sender, EventArgs e)
          {
    
            list.Clear();
    
            foreach (GridViewRow row in GridView1.Rows)
            {
                // Access the CheckBox
                CheckBox cb = (CheckBox)row.FindControl("FriendSelector");
    
                if (cb != null && cb.Checked)
                {
    
                    string friendname = GridView1.Rows[row.RowIndex].Cells[1].Text.ToString();
                    list.Add(friendname);
    
                }
             }
    
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I had some data, for which I want to fit a parametrized model
I am working with some US govt data which has a lengthy list of
I want to keep logs of some things that people do in my app,
I have some conditional formatting styles. I don't want to keep creating new rules
I have a project that requires some configuration files. I want to keep the
I have 3 Linux machines, and want some way to keep the dotfiles in
I have a list of data where I keep e.g. countries with code, name
I want to upload some data from an Android application to Pachube. [Update: For
I am writing C code, in which I am analyzing some data. I have
I've got a WCF service which handles some sensitive data. I'd like to make

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.