大家好,我正在使用下面的代码,并希望使一个按钮可见和不可见的基础上复选框状态。我使用触发器来调用一个事件,在该事件中我将编写代码来使该按钮可见或不可见。如果我使用下面的代码,我得到一个类似"System.InvalidOperationException:在UpdatePanel‘UpdatePanel1’中找不到触发器的ID为'chkDelete‘的控件。“请帮帮我。
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers ="false">
<ContentTemplate>
<asp:GridView ID="gvEventMechanic" runat="server" AutoGenerateColumns="False" PageSize="5"
GridLines="None" AllowSorting="true" BorderWidth="1"
EnableViewState="true" AllowPaging="true">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Disable
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:CheckBox ID="chkDelete" runat="server" AutoPostBack="true" ></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="chkDelete" EventName="CheckBoxEventChanged" />
</Triggers>
</asp:UpdatePanel>发布于 2011-07-07 18:22:11
作为替代方案,为什么不使用客户端环境来实现这一点呢?它更容易,也更本地化。
$('#input[type=checkbox][id*=chkDelete]').change(function(){
$('#button').toggleClass('disabled');
});现在,基于这个类,您可以使用CSS来使按钮变暗,如果它是span或div (自定义按钮)。否则,您可以使用:
$('#input[type=checkbox][id*=chkDelete]').change(function(){
if ($(this).is(':checked'))
{
$('#button').removeAttr('disabled');
}
else
{
$('#button').attr('disabled', 'disabled');
}
});发布于 2012-02-22 20:51:24
这将使您获得删除相应记录所需的所有信息。
// If you bind a list of objects as your data source you can use this to get the
// index into the list.
protected void OnCheckedChanged( Object sender, EventArgs e )
{
if ( sender is CheckBox )
{
// we do this to get the index into the list of the item we want to work with.
CheckBox cb = sender as CheckBox;
GridViewRow gvr = cb.NamingContainer as GridViewRow;
int dataItemIndex = gvr.DataItemIndex; // index into your list, regardless of page
int rowIndex = gvr.RowIndex; // row index in gridview.
}
}发布于 2011-07-07 18:03:22
CheckBox字段<asp:CheckBox ID="chkDelete" runat="server" AutoPostBack="true" ></asp:CheckBox>的ControlId对于每一行都是不同的,这就是它不能将controlId映射到触发器的原因。
我建议你使用checkbox的CheckedChanged事件来触发你的方法。
https://stackoverflow.com/questions/6608721
复制相似问题