DataList and Checkbox
I have checkbox in the DataList. Now I need to execute a code-beh开发者_开发问答ind when the checkbox is ticked. As far as I know the itemcommand in datalist will not triggered when the checkbox is ticked. I even tried to put the onCheckChanged event in the checkbox but it even worse the situation (not just does not trigger the event but also does allow me to tick the checkbox at all).
Does anyone has a solution?
thanks
I just created a DataList with a CheckBox in it like this:
<asp:DataList ID="Datalist1" runat="server" DataSourceID="Sqldatasource1">
<ItemTemplate>
<asp:CheckBox ID="Checkbox1" Text="text" runat="server" OnCheckedChanged="Checkbox1_CheckedChanged" AutoPostBack="true" />
</ItemTemplate>
</asp:DataList>
and this code-behind
protected void Checkbox1_CheckedChanged(object sender, EventArgs e)
{
}
That allowed me to break into the CheckedChanged event without any problem.
Are you setting AutoPostBack="true" on the <asp:CheckBox control? It might fire the ItemCOmmand event, otherwise, you would have to tap into the CheckChanged event for the control on ItemCreated event.
精彩评论