By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,114 Members | 1,570 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,114 IT Pros & Developers. It's quick & easy.

Datagrid - CheckBox!

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.