加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在转发器C#中传递多个选中的复选框值

发布时间:2020-12-16 01:57:32 所属栏目:百科 来源:网络整理
导读:我正在使用Repeater控件在ASPX页面上的 HTML表格中显示数据库表中的数据.还有两个链接按钮Approve和Reject,它们与Repeater方法ItemCommand绑定. 每行的第一列中都有一个复选框.这将使用户能够选择多行并执行批准和拒绝操作.这是代码: asp:Repeater ID="Pend
我正在使用Repeater控件在ASPX页面上的 HTML表格中显示数据库表中的数据.还有两个链接按钮Approve和Reject,它们与Repeater方法ItemCommand绑定.

每行的第一列中都有一个复选框.这将使用户能够选择多行并执行批准和拒绝操作.这是代码:

<asp:Repeater ID="PendingRegRepeater" runat="server" OnItemCommand="PendingRegRepeater_ItemCommand">
                <HeaderTemplate>
                    <table>
                        <thead>
                            <tr>
                                <th>
                                    Select
                                </th>
                                <th>
                                    Customer Name
                                </th>
                                <th>
                                    Space ID
                                </th>
                                <th>
                                    Date
                                </th>
                                <th>
                                    Amount Paid
                                </th>
                                <th>
                                    Pin Code
                                </th>
                                <th>
                                    Payment Method
                                </th>
                                <th>
                                    Action
                                </th>
                            </tr>
                        </thead>
                </HeaderTemplate>
                <ItemTemplate>
                    <tbody>
                        <tr>
                            <td>
                                <asp:CheckBox runat="server" />
                            </td>
                            <td>
                                <%# DataBinder.Eval(Container.DataItem,"CustomerName") %>
                            </td>
                            <td>
                                <%# DataBinder.Eval(Container.DataItem,"SpaceID") %>
                            </td>
                            <td>
                                <%# DataBinder.Eval(Container.DataItem,"TransactionDate") %>
                            </td>
                            <td>
                                <%# DataBinder.Eval(Container.DataItem,"AmountPaid") %>
                            </td>
                            <td>
                                <%# DataBinder.Eval(Container.DataItem,"Pincode") %>
                            </td>
                            <td>
                                <%# DataBinder.Eval(Container.DataItem,"PaymentMethod") %>
                            </td>
                            <td>
                                <asp:LinkButton ID="lnkApprove" CommandName="Approve" CommandArgument='<%# Eval("RRID") %>' Text="Approve" runat="server" ForeColor="Black" Font-Underline="true"></asp:LinkButton>
                                /
                                <asp:LinkButton ID="lnkReject" CommandName="Reject" CommandArgument='<%# Eval("RRID") %>' Text="Reject" runat="server" ForeColor="Black" Font-Underline="true"></asp:LinkButton>
                            </td>
                        </tr>
                    </tbody>
                </ItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>

但是当用户选择多个复选框并按下“批准”或“拒绝”按钮时,我无法想办法处理.编译器不允许我将Check-box的ID属性设置为动态值<%#Eval(“RRID”)%>.请建议处理这种情况.谢谢.

解决方法

将使用您分配给复选框的ID生成复选框的ID.生成的ASP.net将为生成的行中的每个复选框具有唯一ID.

HTML

<asp:CheckBox runat="server" id="checkBoxID" />

代码背后

foreach (RepeaterItem item in PendingRegRepeater.Items)
{
    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
    {
        var checkBox = (CheckBox)item.FindControl("checkBoxID");
        checkBox.Checked = true;
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读