我动态地将复选框控件添加到 GridView 列。在每个 GridView_RowBound() 事件上,都会将复选框添加到列中。还定义了 RowBound() 事件中的 CheckBox_CheckedChanged 事件,如下所示,
Protected Sub GridviewChildItem_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow AndAlso Not String.IsNullOrEmpty(CRMSignCond) Then
Dim lbValue As Label = DirectCast(e.Row.Cells(5).FindControl("lbValue"), Label)
e.Row.Cells(5).Attributes.Add("onmousemove", "Show('" + lbValue.Text + "')")
e.Row.Cells(5).Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor;Hide();")
End If
AddTemplateControls(Nothing, e)
End Sub
Private Sub AddTemplateControls(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
Dim cbTargetSign As New CheckBox
Dim rbConsolidate As New RadioButtonList
Dim tbSignGrp As New TextBox
cbTargetSign.ID = "chkSelect"
cbTargetSign.AutoPostBack = False
cbTargetSign.Checked = True
rbConsolidate.ID = "rbConsolidate"
tbSignGrp.ID = "tbSigningGroup"
tbSignGrp.Width = 25
If Not e.Row.RowIndex = -1 Then
e.Row.Cells(6).Controls.Add(cbTargetSign)
e.Row.Cells(4).Controls.Add(tbSignGrp)
e.Row.Cells(7).Controls.Add(rbConsolidate)
End If
rbConsolidate.RepeatDirection = RepeatDirection.Horizontal
rbConsolidate.Items.Add("Yes")
rbConsolidate.Items.Add("No")
rbConsolidate.Items(1).Selected = CBool(True)
If cbTargetSign.Checked Then
rbConsolidate.Enabled = False
End If
**AddHandler cbTargetSign.CheckedChanged, AddressOf cbTargetSign_CheckedChanged**
End Sub
'复选框- CheckedChanged 事件。
Public Sub cbTargetSign_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
End Sub
每次,当我选中网格中的复选框时,checkedChanged 事件都不会触发。有人指导我如何解决这个问题吗?
注意:我不想将复选框的 AutoPostBack 设置为 TRUE,因为它会使用默认值重新加载整个网格。