473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dynamic CheckBox CheckedChanged event not firing

Hi,
In the ItemDataBound of my datagrid I am creating a checkbox
dynamically. I have the eventhandler defined for CheckedChanged of the
check box. The event is not firing. The grid is bound in the
Page_Prerender method. My code is something like this

Private Sub grdMissingData_ItemDataBound(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
grdMissingData.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
If ((e.Item.Cells(5).Text <> "Yes") And
(rdDataTypes.SelectedIndex = 0)) Then
Dim cbx As New CheckBox

cbx.EnableViewState = True
cbx.AutoPostBack = True
AddHandler cbx.CheckedChanged, AddressOf
Me.CheckBoxChangedEvent

cbx.ID = e.Item.ItemIndex

Dim productIDLabel As Label =
CType(e.Item.Cells(0).FindControl("prodid"), Label)
cbx.Checked =
IsOnscreenItemSelected(productIDLabel.Text.Trim)

'cbx.ID = e.Item.ItemIndex
e.Item.Cells(5).HorizontalAlign =
HorizontalAlign.Center
e.Item.Cells(5).Controls.Add(cbx)
End If

End If
End Sub
Private Sub CheckBoxChangedEvent(ByVal sender As Object, ByVal e As
System.EventArgs)

' Changed Event Method
End Sub

Is there some thing i am missing. Can someone help me.

Thanks
Dilip

Nov 19 '05 #1
2 10764
If the datagrid is bound at the Page_Prerender stage then the veiwstate of
that eventhandler would be lost upon postback. You have to do the datagrid
binding in the page initialization or page loading stages. For a better
understanding
of viewstate during the page life cycle refer to this article on the MSDN
http://msdn.microsoft.com/library/de.../viewstate.asp

If you are waiting for some data until the page_prerender stage to decide on
databinding the datagrid then persist these data in the ViewState or Session
in order to do the databinding during the page_load upon postback and thereby
preserve the viewstate of the events. I have here a sample that demonstrates
this concept:
http://www.societopia.net/Samples/Dy...dControls.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"di*********@gmail.com" wrote:
Hi,
In the ItemDataBound of my datagrid I am creating a checkbox
dynamically. I have the eventhandler defined for CheckedChanged of the
check box. The event is not firing. The grid is bound in the
Page_Prerender method. My code is something like this

Private Sub grdMissingData_ItemDataBound(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
grdMissingData.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
If ((e.Item.Cells(5).Text <> "Yes") And
(rdDataTypes.SelectedIndex = 0)) Then
Dim cbx As New CheckBox

cbx.EnableViewState = True
cbx.AutoPostBack = True
AddHandler cbx.CheckedChanged, AddressOf
Me.CheckBoxChangedEvent

cbx.ID = e.Item.ItemIndex

Dim productIDLabel As Label =
CType(e.Item.Cells(0).FindControl("prodid"), Label)
cbx.Checked =
IsOnscreenItemSelected(productIDLabel.Text.Trim)

'cbx.ID = e.Item.ItemIndex
e.Item.Cells(5).HorizontalAlign =
HorizontalAlign.Center
e.Item.Cells(5).Controls.Add(cbx)
End If

End If
End Sub
Private Sub CheckBoxChangedEvent(ByVal sender As Object, ByVal e As
System.EventArgs)

' Changed Event Method
End Sub

Is there some thing i am missing. Can someone help me.

Thanks
Dilip

Nov 19 '05 #2
You would have to capture this event in the ItemCommand event within
the datagrid. Any button clicked in the datagrid raises this event.

Then you would have to get a reference to the checkbox button by
something like this
CheckBox mycheckbox = (ChackBox) e.Items.Cells(0).Controls(0)

Cells(0) is the very first cell
Contols(0) is the very first control in that cell.

You need to change the ordinals to where the checkbox appears in your
datagrid.

Now that you have a refenence to the checkbox , then you can do
whatever you like.

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Steven | last post by:
I create the checkboxes dynamically on my webform (aspx). after I create them, when I check any of the checkboxes, nothing happens. Here is my code ... ArrayList LayerNameList1 = LayerNameList;...
5
by: Greg Hurlman | last post by:
I've got a very simple ASCX page, where once someone finishes a section and clicks the "Next >" button, the section they just finished is disabled, and the next section appears below it, and so on....
3
by: DotNetJunkies User | last post by:
Hi, I have a checkbox control programmatically created for each row in the datagrid but CheckedChanged event not firing when state of the checkbox changes. I use the following code to...
5
by: Irfan Akram | last post by:
Hi Mr.Steve, First of all many thanks for your kind response. The thing is that I am trying to control the user's action of deselecting a checkbox, once he has selected it. Also the checkbox has...
0
by: louise raisbeck | last post by:
Hi there, I am databinding a datagrid on the onload with the usual !IsPostBack condition. I have to create some dynamic checkboxes, because i dont know how many i will need until the dataset...
0
by: louise raisbeck | last post by:
Hi there, I am databinding a datagrid on the onload with the usual !IsPostBack condition. I have to create some dynamic checkboxes, because i dont know how many i will need until the dataset...
0
by: galien8 | last post by:
Dear Newsgroup Readers, I have a problem with dynamic controls, in a DotNetNuke module, and event handlers in VB.NET ASP.NET 2.0. Events are firing and being handled, sometimes good but also...
0
by: =?Utf-8?B?SWRlcm9ja3M=?= | last post by:
Hi All, I created a dynamic checkbox in ASP .Net inside a Button1_Click event method (outside the page_load event) and performed the event handling method for the CheckedChanged event and I...
1
by: iderocks | last post by:
Hi All, I created a dynamic checkbox in ASP .Net inside a Button1_Click event method (outside the page_load event) and performed the event handling method for the CheckedChanged event and when I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.