Click here to Skip to main content
11,930,018 members (46,499 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET checkbox
hi, i want to get the selected checkboxes inside of asp repeater, but it always return

this is my page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
<!DOCTYPE html>
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:Button Text="Click" runat="server" OnClick="SendEmail"/>
        <table align="center">
                    <div class="widget-block">
                        <div class="widget-head" style="border-removed 0px; margin-removed 0px;">
                            <h5 class="pull-right" style="padding-removed 0px;">لیست مخاطبین</h5>
                        <div class="widget-content">
                            <div class="widget-box" style="width: 700px; min-width: 700px;">
                                    <label id="SendTypeLabel">
                                        نحوه ارسال:
                                    <select runat="server" id="drpSendType" onchange="ChangeSendType();">
                                        <option value="ارسال انتخابی">ارسال انتخابی</option>
                                        <option value="ارسال گروهی">ارسال گروهی</option>
                                <div  runat="server" id="SelectionTable">
                                    <table class="data-tbl-boxy table" id="table5">
                                        <thead id="Thead5"  runat="server" class="tblHeader">
                                                <th>نام خانوادگی</th>
                                                <th>نام گروه</th>
                                        <tbody  runat="server" id="tbodySelection">
                                            <asp:Repeater runat="server" ID="rptSelection">
                                                            <asp:CheckBox ID="SelectionCheckBox" Text='<%#Eval("FirstName")%>' runat="server" ToolTip='<%#Eval("Contact_ID")%>' />
                                                            <asp:Label ID="Label1" runat="server" Text='<%#Eval("FirstName")%>' />
                                                            <asp:Label ID="Label2" runat="server" Text='<%#Eval("LastName")%>' />
                                                            <asp:Label ID="Label3" runat="server" Text='<%#Eval("Email")%>' />
and this is my code:
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
using System.Web.Services;
using System.Globalization;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
public partial class test : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        if (!this.IsPostBack)
            LoadContacts(sender, e);
    protected void LoadContacts(object sender, EventArgs e)
        SqlConnection Connection = new SqlConnection("Data Source=.;Initial Catalog=npg_database_1;Integrated Security=SSPI");
        SqlCommand Command = new SqlCommand("GetContactDetails", Connection);
        Command.CommandType = CommandType.StoredProcedure;
        Command.Parameters.AddWithValue("@action", "GetAllContacts");
        Command.Parameters.AddWithValue("@group_name", "1");
        SqlDataAdapter adapter = new SqlDataAdapter(Command);
        DataSet ds = new DataSet();
        DataTable tableA = ds.Tables[0];
        DataTable tableB = ds.Tables[1];
        rptGroup.DataSource = tableB; //Group Table
        rptSelection.DataSource = tableA; //Selection Table
    protected void SendEmail(object sender, EventArgs e)
        List<long> SelectionIds = new List<long>();
        string Temp;
        for (int i = 0; i < rptSelection.Items.Count; i++)
            CheckBox chk = (CheckBox)rptSelection.Items[i].FindControl("SelectionCheckBox");
            Temp = chk.ID.ToString();
            if (chk.Checked && chk != null)

how can i fix this problem???
Posted 16-Feb-13 21:48pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

SET AutoPostBack Property To True

<asp:CheckBox ID="gchk" Text="" runat="server" ToolTip='<%#Eval("ID")%>' AutoPostBack="True" />
shajarian_lover 17-Feb-13 3:39am
is there another way to fix this problem? i dont want to set AutoPostBack to true, beacause it reloads page again.
Imtiyaz_mi 17-Feb-13 3:42am
By default the value will be false, so we need to set the autopostback property
You can place asp:Repeater control under update panel

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100