0

I am using a repeater :

<asp:Repeater ID="rptAdvertisements" runat="server" OnItemCommand="rptAdvertisements_ItemCommand" >
    <ItemTemplate>        
            <tr <%# Eval("RowStyle")%>>
                <td><input  type="checkbox" DISABLED /></td>
                <td><%# Eval("ADV_Title")%></td>
                <td><%# Eval("ADV_NbView")%></td>
                <td><%# Eval("Date")%></td>
                <td><%# Eval("DateEnd")%></td>
                <td><img src="<%=ResolveClientUrl("~/Images/Advertisements/")%><%# Eval("IMG")%>" alt="<%# Eval("ADV_Title")%>" title="<%# Eval("ADV_Title")%>" style="max-height:100px;max-width:100px;" /></td>  
                <td><input  type="checkbox" id="checkbox1" runat="server"  checked='<%#Convert.ToBoolean(Eval("ADV_Special"))%>'   /></td>
                <td><input  type="checkbox" id="checkbox2" runat="server"  checked='<%#Convert.ToBoolean(Eval("ADV_Info"))%>'   /></td>
                </tr>
    </ItemTemplate>
</asp:Repeater>

How to disable checking checkbox this repeater ?

2

3 Answers 3

1

Cast to bool instead of Convert.ToBoolean

Change

<input  type="checkbox" id="checkbox1" runat="server"  checked='<%#Convert.ToBoolean(Eval("ADV_Special"))%>'   />

To

<input  type="checkbox" id="checkbox1" runat="server"  checked='<%# (bool)(Eval("ADV_Special"))%>'   />
Sign up to request clarification or add additional context in comments.

1 Comment

It doesnt solve the problem:I need to fill the checkboxes at the begining and after the user can not change the checked or unchecked checkbox with the mouseclick.
0

On the basis that you want the checkbox to be permanently disabled, you need to add a disabled attribute to the markup.

e.g.

<input  type="checkbox" disabled id="checkbox1" runat="server" checked='<%#Convert.ToBoolean(Eval("ADV_Special"))%>'   />

EDIT: It appears that your code also doesn't check the checkbox. In order to check the checkbox it just needs to have the checked attribute present or not present (rather than setting it to true/false as you have it).

So, you would need to do the following to display/hide the checked attribute in addition to disabling it:

<input  type="checkbox" id="checkbox1" disabled <%#Convert.ToBoolean(Eval("ADV_Special")) ? "checked" : String.Empty %>  />

NB - to do this you have to take out the runat="server" attribute to stop issues with malformed server controls. If you want to have access to the checkbox in the back-end you could always use an asp:CheckBox instead as follows:

<asp:CheckBox ID="checkbox1" Enabled="false" Checked='<%#Convert.ToBoolean(Eval("ADV_Special"))'  runat="server" />

3 Comments

@ tristankoffee It doesnt solve the problem: with disabled all checkboxes are not checked even if Convert.ToBoolean(Eval("ADV_Special")) == true I need to fill the checkboxes at the begining and after the user can not change the checked or unchecked checkbox with the mouseclick.
@SLNEEBD - that isn't clear from your question. Your question askshow to disable the checkboxes in a repeater. I will update the answer to show you how to check the checkbox.
@SLNEEBD - did that resolve the issue for you? If so, it'd be great if you could mark the question as answered or, if not, provide more information around what's still not working.
0

Old question, but this may help someone:

<input type="checkbox" <%# ((bool)Eval("ShouldCheck") ? "checked='checked' disabled='disabled'" : "") %> />

This example checks a ShouldCheck boolean property of the databound container. If true, it checks the checkbox and disables it. My use case was I wanted the user to be able to check the box only if it wasn't already checked (one-way checkbox).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.