Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, i want to get the selected checkboxes inside of asp repeater, but it always return
HTML
checked="false"


this is my page:
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Button Text="Click" runat="server" OnClick="SendEmail"/>
        <table align="center">
            <tr>
                <td>
                    <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>
                        <div class="widget-content">
                            <div class="widget-box" style="width: 700px; min-width: 700px;">
                                <div>
                                    <label id="SendTypeLabel">
                                        نحوه ارسال:
                                    </label>
                                    <select runat="server" id="drpSendType" onchange="ChangeSendType();">
                                        <option value="ارسال انتخابی">ارسال انتخابی</option>
                                        <option value="ارسال گروهی">ارسال گروهی</option>
                                    </select>
                                </div>
                                <div  runat="server" id="SelectionTable">
                                    <table class="data-tbl-boxy table" id="table5">
                                        <thead id="Thead5"  runat="server" class="tblHeader">
                                            <tr>
                                                <th>انتخاب</th>
                                                <th>نام</th>
                                                <th>نام خانوادگی</th>
                                                <th>ایمیل</th>
                                                <th>نام گروه</th>
                                            </tr>
                                        </thead>
                                        <tbody  runat="server" id="tbodySelection">
                                            <asp:Repeater runat="server" ID="rptSelection">
                                                <ItemTemplate>
                                                    <tr>
                                                        <td>
                                                            <asp:CheckBox ID="SelectionCheckBox" Text='<%#Eval("FirstName")%>' runat="server" ToolTip='<%#Eval("Contact_ID")%>' />
                                                        </td>
                                                        <td>
                                                            <asp:Label ID="Label1" runat="server" Text='<%#Eval("FirstName")%>' />
                                                        </td>
                                                        <td>
                                                            <asp:Label ID="Label2" runat="server" Text='<%#Eval("LastName")%>' />
                                                        </td>
                                                        <td>
                                                            <asp:Label ID="Label3" runat="server" Text='<%#Eval("Email")%>' />
                                                        </td>
                                                        <td>
                                                            <asp:Label ID="Label4" runat="server" Text='<%#Eval("GroupName")%>' />
                                                        </td>
                                                    </tr>
                                                </ItemTemplate>
                                            </asp:Repeater>
                                        </tbody>
                                    </table>
                                </div>
                                <div  runat="server" id="GrouupTable" class="MH">
                                    <table class="data-tbl-boxy table" id="tableGroup">
                                        <thead id="Thead6"  runat="server" class="tblHeader">
                                            <tr>
                                                <th>انتخاب</th>
                                                <th>نام گروه</th>
                                                <th>تعداد افراد</th>
                                            </tr>
                                        </thead>
                                        <tbody  runat="server" id="tbodyGroup">
                                            <asp:Repeater runat="server" ID="rptGroup">
                                                <ItemTemplate>
                                                    <tr>
                                                        <td>
                                                            <asp:CheckBox ID="gchk" Text="" runat="server" ToolTip='<%#Eval("ID")%>' />
                                                        </td>
                                                        <td>
                                                            <asp:Label ID="Label5" runat="server" Text='<%#Eval("GroupName")%>' />
                                                        </td>
                                                        <td>
                                                            <asp:Label ID="Label6" runat="server" Text='<%#Eval("MemberNo")%>' />
                                                        </td>
                                                    </tr>
                                                </ItemTemplate>
                                            </asp:Repeater>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

and this is my code:
C#
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;
        Connection.Open();
        Command.Parameters.AddWithValue("@action", "GetAllContacts");
        Command.Parameters.AddWithValue("@group_name", "1");
        SqlDataAdapter adapter = new SqlDataAdapter(Command);
        DataSet ds = new DataSet();
        adapter.Fill(ds);
        DataTable tableA = ds.Tables[0];
        DataTable tableB = ds.Tables[1];
        rptGroup.DataSource = tableB; //Group Table
        rptGroup.DataBind();
        rptSelection.DataSource = tableA; //Selection Table
        rptSelection.DataBind();
        Connection.Close();
    }

    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)
            {
                SelectionIds.Add(Int64.Parse(chk.ToolTip));
                Response.Write(chk.Text);
            }
        }
    }
}


how can i fix this problem???
Posted

1 solution

SET AutoPostBack Property To True

<asp:CheckBox ID="gchk" Text="" runat="server" ToolTip='<%#Eval("ID")%>' AutoPostBack="True" />
 
Share this answer
 
Comments
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.
mimtiyaz 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900