复选框不起作用 [英] Checkbox does not work

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

问题描述

我将在转发器中使用复选框,但它始终显示False。我必须同时扮演角色和子角色,首先我会为角色做代码。但是复选框显示总是假值。



我尝试了什么:



I will use checkbox in repeater but it always shows "False". I have to both role and their subrol and first i will do code for role.but checkbox shows always false value.

What I have tried:

<asp:Repeater ID="rptrrol" runat="server" OnItemDataBound="rptrrol_ItemDataBound">
                   <ItemTemplate>

                       <dl>
                           <dt>

                               <button id="btn"  runat="server">+</button><asp:CheckBox ID="chkrole" runat="server" CssClass="topic" Text='<%#Eval("role") %>' ValidationGroup="user" AutoPostBack="true" Checked='<%# Eval("role")%>' />

                               <asp:Repeater ID="rptrsubrole" runat="server">
                                   <ItemTemplate>
                                       <dd style="margin-removed 10px;">
                                           <asp:CheckBox ID="chksubrole" runat="server" Text='<%#Eval("role") %>' ValidationGroup="user" />
                                           <br />

                                       </dd>
                                   </ItemTemplate>
                               </asp:Repeater>
                           </dt>
                       </dl>

                   </ItemTemplate>
               </asp:Repeater>







c#code




c# code

protected void btnsave_Click(object sender, EventArgs e)
{
 foreach (RepeaterItem item in rptrrol.Items)
        {
            CheckBox ch = item.FindControl("chkrole") as CheckBox;

            if (ch != null && ch.Checked == true)
            {
                ch.Text = "IT is selected now";
            }
        }
}

推荐答案

您没有设置Checked属性,因此当然,转发器中的所有复选框都将被取消选中。



您需要添加
You aren't setting the Checked property, so of course all the checkboxes in the repeater will be unchecked.

You need to add
Checked='<%# Eval("ObjectCheckedBooleanProperty") #>'

进入商品模板中的复选框定义。

into your checkbox definition in the item template.


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

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