0

I added checkbox control to the GridView column dynamically. On each GridView_RowBound() event, checkbox is being added to the column. Also defined, CheckBox_CheckedChanged event in the RowBound() event as below,

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

'Checkbox- CheckedChanged event.

Public Sub cbTargetSign_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)

End Sub

Every time, when i check the checkbox in the grid, checkedChanged event doesn't trigger. Anyone guide me how to resolve this ?

Note: I don't want to set AutoPostBack of checkbox to TRUE since it reloads the entire grid with default values.

enter image description here

VHK
  • 193
  • 2
  • 4
  • 12
  • When are you expecting the `checkedChanged` to trigger? Because you set autopostback to false it will only fire on the next PostBack by another control. – VDWWD May 17 '17 at 14:11
  • I want to Disable other template controls (Radio button and textbox) added in the grid upon the CHECKED. After setting AutoPostBack to TRUE, on CheckBox click, CheckedChanged event is fired. Upon UnCheck it's not triggred. Later, i set Checked = True on page load, now event is triggered when Unchecked and not when Checked. May i know the reason for this behavior ? – VHK May 17 '17 at 14:22
  • Are you adding the dynamic controls on every page load (and that includes a postback). If not then it wil fail the second time. – VDWWD May 17 '17 at 14:27
  • Yes, adding them on every page load. – VHK May 17 '17 at 14:32

1 Answers1

0

If you don't want to set AutoPostBack of checkbox to TRUE since it reloads the entire grid with default values, you will try set AutoPostBack="True" and:

`<`asp:UpdatePanel ID="itemPanel" runat="server" UpdateMode="Conditional"`>`<br/>
                `<`ContentTemplate`>`<br/>
                   //your controls<br/>
               `<`/ContentTemplate`>`<br/>
`<`/asp:UpdatePanel`>`
BlackBeard
  • 10,246
  • 7
  • 52
  • 62