我在使用 checkchanged 事件处理程序时遇到问题。以下是我的场景:
我有一个 aspxcheckbox,它位于一个 DataItemTemplate 内部,它位于一个 aspxgridview 内部的 gridviewdatacheckcolumn 内部。
这是我的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的,所以我必须使用插入语句而不是将字段绑定到表。
请让我知道您是否可以提供帮助或我是否需要澄清任何事情。谢谢你!