我有一个 asp.net 应用程序,我在用户控件中添加了中继器,并在中继器中添加了asp Checkbox
<asp:Repeater ID="Repeater1" runat="server"
onitemdatabound="Repeater1_ItemDataBound"
onitemcommand="Repeater1_ItemCommand" >
<ItemTemplate>
<table>
<tr>
<td>
<asp:CheckBox runat="server" ID="chkSelect" AutoPostBack="true" Visible="false" OnCheckedChanged="chkSelect_CheckedChanged" />
</td>
在 CodeBehind 文件中:
protected void chkSelect_CheckedChanged(object sender, EventArgs e)
{
string s = "";
}
但是单击复选框时该事件不会触发。
我还尝试在 Repeater 控件的 itemDataBound 事件触发时动态添加事件:
<asp:Repeater ID="Repeater1" runat="server"
onitemdatabound="Repeater1_ItemDataBound"
onitemcommand="Repeater1_ItemCommand" >
<ItemTemplate>
<table>
<tr>
<td>
<asp:CheckBox runat="server" ID="chkSelect" AutoPostBack="true" Visible="false" />
</td>
在后面的代码中:
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (((DataRowView)e.Item.DataItem).Row["DataType"].ToString().Trim().Equals("bool"))
{
CheckBox chkSelect = (CheckBox)e.Item.FindControl("chkSelect");
chkSelect.CheckedChanged += new EventHandler(chkSelect_CheckedChanged);
chkSelect.Visible = true;
}
但仍然没有触发事件..
如何调用Repeater Control内部的CheckBox控件事件...