Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can i add items which are checked to arraylist in Gridview c# asp.net
    primarykey
    data
    text
    <p>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</p> <pre><code> // 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 &amp;&amp; cb.Checked) { string friendname = GridView1.Rows[row.RowIndex].Cells[1].Text.ToString(); for (int i = 0; i &lt; 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 &lt; 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); } } } } &lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Font-Bold="True" Width="157px"&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText="Select"&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox runat="server" id="FriendSelector" oncheckedchanged="SelectedFriends_Click" AutoPostBack="True"&gt; &lt;/asp:CheckBox&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField DataField="F_Name" HeaderText="Friend Name" SortExpression="F_Name" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload