Click here to Skip to main content
15,888,320 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

XML
<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#
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";
            }
        }
}
Posted
Updated 23-Jun-16 19:13pm
v4
Comments
[no name] 22-Jun-16 6:24am    
use item template before checkbox control.
Vibhusha Devani 24-Jun-16 1:18am    
it's not work in this code.please give other solution if possible.
phil.o 22-Jun-16 6:25am    
That's a CheckBox ; having a text "Selected" for it, along with the fact that it is checked or not, should be sufficient as a visual indication of the state.

1 solution

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.
 
Share this answer
 
Comments
Maciej Los 23-Jun-16 15:27pm    
5!
Vibhusha Devani 24-Jun-16 1:14am    
i will be try this but still it shows error like , Specified cast is not valid.

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

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