Results 1 to 2 of 2

Thread: [RESOLVED] [02/03] AddHandler to CheckBox in datagrid

  1. #1

    Thread Starter
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Resolved [RESOLVED] [02/03] AddHandler to CheckBox in datagrid

    I've got the following item in my grid
    Code:
    <ItemTemplate>
    	<asp:CheckBox Checked='<%# DataBinder.Eval(Container.DataItem, "Status") %>' ID="chkNpi" Runat="server" 
    	AutoPostBack="True" Text='<%# DataBinder.Eval(Container.DataItem, "NPI") %>' />
    </ItemTemplate>
    And the following code in my code behind, but my check changed event never fires. The addHandler code is being executed in the ItemDataBound event. Any ideas?
    vb Code:
    1. Public Sub dgProvider_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
    2.     Handles dgProvider.ItemDataBound
    3.         Dim chkNpi As Control = e.Item.FindControl("chkNpi")
    4.         If Not chkNpi Is Nothing Then
    5.             AddHandler DirectCast(chkNpi, CheckBox).CheckedChanged, AddressOf chkNpi_CheckedChanged
    6.         End If
    7.     End Sub
    8.  
    9.     Public Sub chkNpi_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    10.         Dim busProvider As New BCBSMT.ProviderBC
    11.     End Sub

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [02/03] AddHandler to CheckBox in datagrid

    But that's a dynamic handler. You've added it yourself and I don't think it will maintain its viewstate because you created it in ItemDataBound. ItemDataBound isn't called everytime, is it?

    You must do your AddHandler in the ItemCreated event of 'dgProvider'. Or, I think you can also specify OnCheckChanged as an event handler in the asp:checkbox in the ItemTemplate itself.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width