Domanda

I've got a repeater and inside on of the tags I've got a checkbox, which .Checked property I want to set inside the ItemDataBound event of the repeater. The problem is that args.Item.FindControl("checkboxSelect"); returns me null.

Here is the HTML:

<asp:Repeater ID="productRepeater" runat="server" OnItemDataBound="productRepeater_ItemDataBound">
    <ItemTemplate>
        <tr class="hand">                                
            <td class="hyperLink center-text width50px">
                <fieldset data-role="controlgroup" id="divCheckbox">
                    <input type="checkbox" name="checkboxSelect" id="checkboxSelect" class="custom" />
                    <label for="checkboxSelect">
                    </label>
                </fieldset>                                    
            </td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

And the productRepeater_ItemDataBound method:

protected void productRepeater_ItemDataBound(object sender, RepeaterItemEventArgs args)
{
    CheckBox checkboxSelect = (CheckBox)args.Item.FindControl("checkboxSelect");
}

I assume that what causes the problem is <fieldset data-role="controlgroup" id="divCheckbox">, because in the other <td> in the repeater (not shown) I've got no problems finding the controls. Any suggestions how to get the control in the current situation?

È stato utile?

Soluzione

FindControl is only capable of finding server-side controls, not plain HTML tags. Therefore in this particular Repeater it is not likely to find anything. However you can always turn HTML tag into server-side control with runat:

<input runat="server" type="checkbox" name="checkboxSelect" id="checkboxSelect" class="custom" />

Now every checkboxSelect will be added into collection of controls, and FindControl will be able to find it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top