OnCheckedChanged事件不触发在GridView中 [英] OnCheckedChanged event not firing in GridView at all

查看:408
本文介绍了OnCheckedChanged事件不触发在GridView中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GridView与一个asp复选框在一个TemplateField。 TemplateField定义如下:

 < asp:TemplateField HeaderText =HeaderName> 
< ItemTemplate>
< asp:CheckBox ID =checkBoxIdrunat =serverOnCheckedChanged =MyCheckChangedMethodAutoPostBack =true/>
< / ItemTemplate>
< / asp:TemplateField>

当我在MyCheckChangedMethod中使用断点运行我的web项目时,点击复选框不会发生。断点没有命中。我的Visual Studio调试器正在运行。



此外,在我的页面定义中,我有AutoEventWireup = True,所以我不必手动挂接事件。我从来没有一个问题这样做这种方式。



有什么想法吗?

$ b。我有一个按钮在同一页面上设置完全相同的方式与点击事件, $ b

解决方案

复选框控件的回发事件将不会正确触发,因为它在一个GridView中,它损坏控件的ID。



如果您需要使用复选框来反映数据,您可以使用 CheckBoxField 对象并以这种方式绑定。



如果需要,执行操作对于该行,您可能需要查看 ButtonField 对象使用 CommandName 属性和 RowCommand 事件。



a href =http://www.asp.net/Learn/data-access/tutorial-52-vb.aspx =nofollow noreferrer>访问GridView服务器端的复选框。 p>

I have a GridView with an asp CheckBox in a TemplateField. The TemplateField is defined as follows:

<asp:TemplateField HeaderText="HeaderName">
    <ItemTemplate>
        <asp:CheckBox ID="checkBoxId" runat="server" OnCheckedChanged="MyCheckChangedMethod" AutoPostBack="true"/>
    </ItemTemplate>
</asp:TemplateField>

When I run my web project with a breakpoint inside MyCheckChangedMethod and click the checkbox nothing happens. The breakpoint is not hit. My Visual Studio debugger is running.

Additionally, I have AutoEventWireup = True in my page defnition so I don't have to manually hook up the event. I have never had a problem doing it this way before. I have a button on the same page setup the exact same way with a click event and the breakpoint gets hit fine in that.

Any ideas?

解决方案

The postback event for the checkbox control won't fire correctly because it's within a GridView that mangles the ID of the control.

If you need the Checkbox to reflect data you can use the CheckBoxField object and bind that way.

If you need it perform an action for the row, you may want to look at the ButtonField object using the CommandName property and the RowCommand event.

There are ways to access the checkboxes within the GridView server side.

这篇关于OnCheckedChanged事件不触发在GridView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆