473,403 Members | 2,071 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,403 software developers and data experts.

Datagrid - CheckBox!

Hi all,

I have a datagrid with a checkbox in one column.
The checkbox is set to autopostback and calls a method named
UpdateMailSubscribers.

The first click on the checkbox cause the page to post but doesn't seem to
haven't any affect.
It doesn't appear to call the UpdateMailSubscribers method.

Relevant Code Below:

<asp:CheckBox AutoPostBack="true" OnCheckedChanged="UpdateMailSubscribers"
Runat="server"/>

Sub dgEmps_OnItemDataBound(ByVal Sender As Object, ByVal e As
DataGridItemEventArgs)

'variable declaration
Dim lbtnDelete As LinkButton

'ensure current data grid row is not a header or footer
If(e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <>
ListItemType.Footer AND dgEmps.EditItemIndex = -1) Then

'determine if account belongs to selected mail group
If(DsEmps.Tables(0).Rows(e.Item.ItemIndex).Item("a smt_mail_subscriber_id").GetType.ToString
<> "System.DBNull") Then

'assign checkbox id "asmt_mail_subscriber_id"; used for
deletion
CType(e.Item.Cells(0).Controls(1),CheckBox).ID =
DsEmps.Tables(0).Rows(e.Item.ItemIndex).Item("asmt _mail_subscriber_id")
CType(e.Item.Cells(0).Controls(1),CheckBox).Checke d =
True

Else

'assign checkbox id "account id"; used for insertion
CType(e.Item.Cells(0).Controls(1),CheckBox).ID =
dgEmps.DataKeys(e.Item.ItemIndex)
CType(e.Item.Cells(0).Controls(1),CheckBox).Checke d =
False

End If

End If

End If

End Sub

Sub UpdateMailSubScribers(ByVal sender As Object, e As System.EventArgs)

'variable declaration
Dim chkMailSubscriber As CheckBox
Dim cmdDelete As SqlCommand
Dim cmdInsert As SqlCommand

chkMailSubscriber = CType(sender,CheckBox)

'determine if an account mail subscription is being added or removed
If(chkMailSubscriber.Checked = False) Then

'delete account subscription stored procedure

'rebind datagrid to datasource
dgEmps_BindData()
Else

'insert account subscription stored procedure

'rebind datagrid to datasource
dgEmps_BindData()

End If

lblDebug.Text = "Sender:" & CType(sender,CheckBox).Checked

End Sub
Nov 19 '05 #1
2 3016
Hi Adam,

Add the following to your dgEmps_OnItemDataBound method:

Dim chk As CheckBox = CType(e.Item.Cells(0).Controls(1),CheckBox)
AddHandler chk.CheckedChanged, AddressOf UpdateMailSubScribers

--
HTH,
Phillip Williams
http://www.societopia.net/Samples
http://www.societopia.net
http://www.webswapp.com
"Adam Knight" wrote:
Hi all,

I have a datagrid with a checkbox in one column.
The checkbox is set to autopostback and calls a method named
UpdateMailSubscribers.

The first click on the checkbox cause the page to post but doesn't seem to
haven't any affect.
It doesn't appear to call the UpdateMailSubscribers method.

Relevant Code Below:

<asp:CheckBox AutoPostBack="true" OnCheckedChanged="UpdateMailSubscribers"
Runat="server"/>

Sub dgEmps_OnItemDataBound(ByVal Sender As Object, ByVal e As
DataGridItemEventArgs)

'variable declaration
Dim lbtnDelete As LinkButton

'ensure current data grid row is not a header or footer
If(e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <>
ListItemType.Footer AND dgEmps.EditItemIndex = -1) Then

'determine if account belongs to selected mail group
If(DsEmps.Tables(0).Rows(e.Item.ItemIndex).Item("a smt_mail_subscriber_id").GetType.ToString
<> "System.DBNull") Then

'assign checkbox id "asmt_mail_subscriber_id"; used for
deletion
CType(e.Item.Cells(0).Controls(1),CheckBox).ID =
DsEmps.Tables(0).Rows(e.Item.ItemIndex).Item("asmt _mail_subscriber_id")
CType(e.Item.Cells(0).Controls(1),CheckBox).Checke d =
True

Else

'assign checkbox id "account id"; used for insertion
CType(e.Item.Cells(0).Controls(1),CheckBox).ID =
dgEmps.DataKeys(e.Item.ItemIndex)
CType(e.Item.Cells(0).Controls(1),CheckBox).Checke d =
False

End If

End If

End If

End Sub

Sub UpdateMailSubScribers(ByVal sender As Object, e As System.EventArgs)

'variable declaration
Dim chkMailSubscriber As CheckBox
Dim cmdDelete As SqlCommand
Dim cmdInsert As SqlCommand

chkMailSubscriber = CType(sender,CheckBox)

'determine if an account mail subscription is being added or removed
If(chkMailSubscriber.Checked = False) Then

'delete account subscription stored procedure

'rebind datagrid to datasource
dgEmps_BindData()
Else

'insert account subscription stored procedure

'rebind datagrid to datasource
dgEmps_BindData()

End If

lblDebug.Text = "Sender:" & CType(sender,CheckBox).Checked

End Sub

Nov 19 '05 #2
One thing i should mention:

After the initial click everything works as expected.
The required method is called and the necessary db activity is performed;
everything works as it should.

Cheers,
Adam
Nov 19 '05 #3

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

Similar topics

0
by: Just D | last post by:
Hi All, Does anybody know how to write the following code? I have a database table with a few columns including: ID , "Task" , ForceRun . I need to show the DataGrid on the ASPX page with...
4
by: Jim Heavey | last post by:
Hello, I am starting to learn how to use the Datagrid and I have a couple of questions. My datagrid as a checkbox in it. It looks like the following in the datagrid... <asp:TemplateColumn...
2
by: Sebi | last post by:
Hello all is it possible to add a checkbox in a DataGrid for Boolean Data? Thanks in advance
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
4
by: Mike | last post by:
Hi, Is there a possibility to have one of the Web Control Datagrid's column as a Calendar when editing data? Any resources on this subject? Thanks Mike
7
by: Lars Netzel | last post by:
If I put a checkbox in a datagrid (ASP.NET) and set the Autopostback to true I can catch OnChange event on checkbox but how do I then catch what DataGridItemIndex is? Can I use some Event in the...
2
by: Mortar | last post by:
i have a datagrid with 2 columns. the 1st column contains an id which will be used by the database for the selected checkbox records. the 2nd column is a template column containing a server...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
3
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method...
7
by: rn5a | last post by:
The first column of a DataGrid has a CheckBox for all the rows. I want that when users check a CheckBox, the BackColor of that entire row in the DataGrid should change to a different color. To...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.