Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net OnCheckedChange事件不执行my事件_Asp.net_Vb.net_Treeview_Autopostback_Oncheckedchanged - Fatal编程技术网

Asp.net OnCheckedChange事件不执行my事件

Asp.net OnCheckedChange事件不执行my事件,asp.net,vb.net,treeview,autopostback,oncheckedchanged,Asp.net,Vb.net,Treeview,Autopostback,Oncheckedchanged,我在这里读了一些帖子,其中一些与我的问题有关,但由于某些原因,提供的解决方案对我不起作用。基本上我有两个带有复选框的GridView控件。它们有完全相同的代码,但只是触发不同的事件。当然,它们有不同的ID和相关的唯一信息。奇怪的是,其中一个很好用,另一个不行。我将在这里发布这两个内容,请记住,ID为=“UnassignElegibilityChk”的是无法工作的onte。我已经设置了断点,以测试当我从检查发送回发时,我是否在函数中,而什么都没有 注意:这两个TreeView都在同一页上,因此请假

我在这里读了一些帖子,其中一些与我的问题有关,但由于某些原因,提供的解决方案对我不起作用。基本上我有两个带有复选框的GridView控件。它们有完全相同的代码,但只是触发不同的事件。当然,它们有不同的ID和相关的唯一信息。奇怪的是,其中一个很好用,另一个不行。我将在这里发布这两个内容,请记住,ID为=“UnassignElegibilityChk”的是无法工作的onte。我已经设置了断点,以测试当我从检查发送回发时,我是否在函数中,而什么都没有

注意:这两个TreeView都在同一页上,因此请假定codebehind指令和所有设置都已正确分配给该页(因为其中一个正在工作,我假定没有问题)

这是一个不起作用的:

   <table><tr><td class="style1">
    <asp:GridView ID="ElegibilitySelectedGridview" runat="server" 
        AutoGenerateColumns="False" DataKeyNames="ID" CellPadding="4" 
        ForeColor="#333333" GridLines="None" Width="475px">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    <Columns>
        <asp:TemplateField HeaderText="ID">
            <ItemTemplate>
                <asp:Label ID="lblID0" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Select">
            <ItemTemplate>
                <asp:CheckBox ID="UnassignElegibilityChk" runat="server"  AutoPostBack="true" OnCheckedChanged="UnAssignElegibilityRecord"/>
            </ItemTemplate>                   
        </asp:TemplateField>
        <asp:boundfield datafield="Name"  HeaderText="Elegible Item" />
        </Columns>
        <EditRowStyle BackColor="#999999" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#E9E7E2" />
        <SortedAscendingHeaderStyle BackColor="#506C8C" />
        <SortedDescendingCellStyle BackColor="#FFFDF8" />
        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
    </asp:GridView>
    </td></tr></table>
不工作的人应该触发此代码,但事实并非如此

Public Sub UnAssignElegibilityRecord(ByVal sender As Object, ByVal e As System.EventArgs)
    PrintLine("Inside the sub")
    If Page.IsPostBack Then
        For Each row As GridViewRow In ElegibilitySelectedGridview.Rows
            Dim checkbox As CheckBox = CType(row.FindControl("UnassignElegibilityChk"), CheckBox)
            'Check if the checkbox is checked.'
            'value in the HtmlInputCheckBox Value property is set as the //value of the delete commands parameter.'
            If checkbox.Checked Then
                ' Retreive the Employee ID'
                Dim lblID As Label = CType(row.FindControl("lblID0"), Label)
                Dim elegibilityID As Integer = Convert.ToInt32(lblID.Text)
                Elegibility.RemoveElegibilityMapping(elegibilityID)
                ElegibilitySelectedItems(CInt(Request("ResID")))
                ElegibilityGroupDDL_SelectedIndexChanged()
            End If
        Next
    End If
End Sub

我不知道下面这些是否能解决你的问题,但是

  • 为什么CheckedChanged的“工作”处理程序的签名错误?它需要发送者和事件标记

    受保护的子可分配性(ByVal sender作为对象,ByVal e作为System.EventArgs)

  • 为什么要迭代网格行以获取复选框和已更改的行?这也适用于:

    Dim checkbox As checkbox=DirectCast(发件人,复选框)

  • 要获取该行,只需将复选框的NamingContainer强制转换为GridViewRow即可

    Dim row as GridViewRow=DirectCast(复选框.NamingContainer,GridViewRow)

    编辑:是否在回发时重新绑定ElegibilitySelectedGridview网格?
    只有在
    而不是Page.IsPostback
    时,你才应该这样做,否则事件不会发生。

    @Jovanky-添加“请帮助”不会让人们更快地回答你。我的朋友,有些事情是第二天性。请不要注意这些细节。生活要简单得多。祝你愉快!您没有两个TreeView,而是两个GridView。奇怪的是,您所说的正在工作的方法不接受任何参数,而不工作的方法接受任何参数(
    发送者作为对象,e作为事件参数)。这些方法确实正确吗?您的页面声明中是否包含了
    AutoEventWireup=“True”
    。@Tim,感谢您的更正(编辑),@Graham,AutoEventWireup在我的页面上是false(但一个GridView工作正常)。至于发送方作为对象,即非工作事件上的事件args,这只是试图使其启动,但没有发生任何事情,它甚至没有尝试调用该事件。嗨,Tim,谢谢你的帮助,但我已将(ByVal发送方作为对象,ByVal e作为System.EventArgs)分配给工作事件,只是为了保持一致性,但它没有改变任何事情。此外,在迭代视图时,我可以研究一下,一旦事件至少触发,我想首先集中精力修复它。你让我感到困惑。您的工作处理程序实际上具有错误的签名:
    公共子可分配性()
    。这将导致运行时错误“没有与委托子EventHandler兼容的签名(发送者作为对象,e作为System.EventArgs)”。好的,Tim,但即使没有签名,它也可以工作。我也采纳了你的建议,并按照你的建议添加了相应的签名。然而,仍然没有结果。所以签名问题现在消失了,因为它现在就在那里。你知道为什么这件事没有被解雇吗?我提到这一点是因为这种奇怪的行为是显而易见的,可能表明某些事情是严重错误的,或者至少你没有提到。顺便说一句,我已经更新了我的答案。蒂姆,谢谢你一直支持我。您为我解决了这个问题,我正在重新连接页面加载上的GridView,周围没有任何条件。非常感谢你的帮助!
     Public Sub AssignElegibility()
        If Page.IsPostBack Then
            For Each row As GridViewRow In ElegibilityGridView.Rows
                Dim checkbox As CheckBox = CType(row.FindControl("AssignElegibilityChk"), CheckBox)
                'Check if the checkbox is checked.'
                'value in the HtmlInputCheckBox Value property is set as the //value of the delete commands parameter.'
                If checkbox.Checked Then
                    ' Retreive the Employee ID'
                    Dim lblID As Label = CType(row.FindControl("lblID"), Label)
                    Dim elegibilityID As Integer = Convert.ToInt32(lblID.Text)
                    Elegibility.AddElegibilityMapping(CInt(Request("ResID")), elegibilityID)
                    ElegibilitySelectedItems(CInt(Request("ResID")))
                    ElegibilityGroupDDL_SelectedIndexChanged()
                End If
            Next
        End If
    End Sub
    
    Public Sub UnAssignElegibilityRecord(ByVal sender As Object, ByVal e As System.EventArgs)
        PrintLine("Inside the sub")
        If Page.IsPostBack Then
            For Each row As GridViewRow In ElegibilitySelectedGridview.Rows
                Dim checkbox As CheckBox = CType(row.FindControl("UnassignElegibilityChk"), CheckBox)
                'Check if the checkbox is checked.'
                'value in the HtmlInputCheckBox Value property is set as the //value of the delete commands parameter.'
                If checkbox.Checked Then
                    ' Retreive the Employee ID'
                    Dim lblID As Label = CType(row.FindControl("lblID0"), Label)
                    Dim elegibilityID As Integer = Convert.ToInt32(lblID.Text)
                    Elegibility.RemoveElegibilityMapping(elegibilityID)
                    ElegibilitySelectedItems(CInt(Request("ResID")))
                    ElegibilityGroupDDL_SelectedIndexChanged()
                End If
            Next
        End If
    End Sub