aspxcheckbox checkedchanged事件处理程序未触发的问题

时间:2013-11-04 22:49:09

标签: asp.net vb.net devexpress

我在使用checkedchanged事件处理程序时遇到问题。 以下是我的情景:

我有一个位于DataItemTemplate内的aspxcheckbox  这是在gridviewdatacheckcolumn内部  这是在aspxgridview中。

这是我的aspx代码:

<dx:ASPxGridView ID="gvCustomerCertificates" runat="server" AutoGenerateColumns="False" Caption="Customer Certificates" Width="100%">
                                <Columns>
                                    <dx:GridViewDataTextColumn FieldName="CertNo" ShowInCustomizationForm="True" 
                                        VisibleIndex="1" ReadOnly="True">
                                        <HeaderStyle Font-Bold="True"></HeaderStyle>
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn FieldName="CustManufacturer" Caption="Manufacturer" ShowInCustomizationForm="True"
                                        VisibleIndex="2" ReadOnly="True">
                                        <HeaderStyle Font-Bold="True"></HeaderStyle>
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn FieldName="CustDesc" Caption="Description" 
                                        ShowInCustomizationForm="True" VisibleIndex="3" ReadOnly="True">
                                        <HeaderStyle Font-Bold="True"></HeaderStyle>
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn FieldName="CustModel" Caption="Model" 
                                        ShowInCustomizationForm="True" VisibleIndex="4" ReadOnly="True">
                                        <HeaderStyle Font-Bold="True"></HeaderStyle>
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn FieldName="CustSerialNo" Caption="Serial No" ShowInCustomizationForm="True"
                                        VisibleIndex="5" ReadOnly="True">
                                        <HeaderStyle Font-Bold="True"></HeaderStyle>
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn FieldName="CustControlNo" Caption="Control No" ShowInCustomizationForm="True"
                                        VisibleIndex="6" ReadOnly="True">
                                        <HeaderStyle Font-Bold="True"></HeaderStyle>
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataDateColumn FieldName="CalDate" ShowInCustomizationForm="True"
                                        VisibleIndex="7" ReadOnly="True">
                                        <PropertiesDateEdit DisplayFormatString="MM/dd/yyyy">
                                        </PropertiesDateEdit>
                                        <HeaderStyle Font-Bold="True" />
                                    </dx:GridViewDataDateColumn>
                                    <dx:GridViewDataTextColumn FieldName="CustAssetNo" Caption="Asset No" ShowInCustomizationForm="True"
                                        VisibleIndex="8" ReadOnly="True">
                                        <HeaderStyle Font-Bold="True"></HeaderStyle>
                                    </dx:GridViewDataTextColumn>


                                     <dx:GridViewDataCheckColumn FieldName="Verified" Caption="Verified" ShowInCustomizationForm="True"
                                        VisibleIndex="9" >

                                        <HeaderStyle Font-Bold="True"></HeaderStyle>
                                        <DataItemTemplate>
                                            <dx:ASPxCheckBox ID="chk" runat="server" AutoPostBack="True" OnCheckedChanged="check_Changed" ClientInstanceName="chk" Enabled="True" >
                                            </dx:ASPxCheckBox>
                                         </DataItemTemplate>       


                                    </dx:GridViewDataCheckColumn>


                                    <dx:GridViewDataTextColumn FieldName="VerifiedInitials" Caption="Initials" ShowInCustomizationForm="True"
                                        VisibleIndex="10">
                                        <HeaderStyle Font-Bold="True"></HeaderStyle>
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataHyperLinkColumn FieldName="PDFName" Caption="PDF" ShowInCustomizationForm="True"
                                        VisibleIndex="11" ReadOnly="True">
                                        <HeaderStyle Font-Bold="True"></HeaderStyle>
                                        <PropertiesHyperLinkEdit Target="_blank" Text="View">
                                            <Style ForeColor="#1FB259"></Style>
                                        </PropertiesHyperLinkEdit>
                                    </dx:GridViewDataHyperLinkColumn>
                                </Columns>
                                <Settings ShowFilterBar="Visible" ShowFilterRow="True" ShowHeaderFilterButton="True" />
                                <SettingsText EmptyDataRow="Currently no Certificates available for your account." />


                            </dx:ASPxGridView>

我试图让checkedChanged事件在后面的代码中调用方法“Check_Changed”,但事件处理程序永远不会被触发。

这是我后面代码中的check_Changed方法:

Protected Sub check_Changed(ByVal sender As System.Object, ByVal e As System.EventArgs)

    'test to see if event handler is firing
    MsgBox("Hey")

    Dim cb As ASPxCheckBox = TryCast(sender, ASPxCheckBox)

    Dim container As GridViewDataItemTemplateContainer = TryCast(cb.NamingContainer, GridViewDataItemTemplateContainer)
    cb.ClientInstanceName = String.Format("cbCheck{0}", container.VisibleIndex)
    cb.Checked = gvCustomerCertificates.Selection.IsRowSelected(container.VisibleIndex)


    ' creates a sql connection and opens it
    Dim scSQLConnection As SqlConnection = New SqlConnection() With {.ConnectionString = ConfigurationManager.ConnectionStrings.Item("Main").ConnectionString}
    scSQLConnection.Open()

    ' create a data table
    Try

        Dim sqlCommand As New SqlCommand() With {.CommandText = "INSERT INTO tblVerified VALUES (" + gvCustomerCertificates.Columns.Item("CertNo").ToString}

        Dim daCommand As SqlDataAdapter = New SqlDataAdapter(sqlCommand)
        daCommand.SelectCommand.Connection = scSQLConnection
        sqlCommand.CommandTimeout = 0
        sqlCommand.ExecuteNonQuery()

    Catch ex As Exception

    Finally

    End Try

    scSQLConnection.Close()

End Sub

目前我所要做的就是让msgbox出现,以便我知道事件正在被触发,我的最终目标是在单击复选框时将记录插入数据库,我将记录插入到不同于绑定到gridview的表,所以我必须使用insert语句,而不是将字段绑定到表。

如果您能提供帮助,或者我需要澄清任何事情,请告诉我。 谢谢!

1 个答案:

答案 0 :(得分:0)

我遇到了一个类似的问题,即下拉列表没有触发selectedItemChanged事件。对我来说没有任何帮助,直到我发现,IE11有一些事件的问题。也许这是对你问题的简短回答。