获取ASP Repeater中的选中复选框 [英] Get Selected checkboxes inside ASP Repeater

查看:49
本文介绍了获取ASP Repeater中的选中复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在asp转发器中获取所选复选框,但它总是返回

i want to get the selected checkboxes inside of asp repeater, but it always return

checked="false"





这是我的页面:



this is my page:

<%@ 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:


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;
        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???



how can i fix this problem???

推荐答案

SET AutoPostBack Property To True



SET AutoPostBack Property To True

<asp:CheckBox ID="gchk" Text="" runat="server" ToolTip=''<%#Eval("ID")%>'' AutoPostBack="True" />


这篇关于获取ASP Repeater中的选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆