Datagrid - CheckBox!

A

Adam Knight

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("asmt_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).Checked =
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).Checked =
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
 
A

Adam Knight

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top