Gridview Event Procedures

G

Guest

My ASP.Net 2.0 application uses a GridView control containing a template
consisting of a checkbox and a Text property that I use to store a value to
pass to a SQL statement in the OnCheckChanged event, whose code is as follows:

If sender.checked = True Then
insVal = "'" & Me.Calendar1.SelectedDate.ToShortDateString & "'"
Else
insVal = "Null"
End If

'Get TaskID
TaskID = sender.text


sql = "update tblTask set DateDone = " & insVal & _
" where TaskID = " & TaskID

Try
dbConn.Open()

'Update database
dCmd = New SqlCommand(sql, dbConn)
RowsAffected = dCmd.ExecuteNonQuery

Catch ex As Exception
'...

Finally
If Not IsNothing(dbConn) Then
dbConn.Close()
End If
End Try

Me.gridDoList.DataBind()

This works fine if only a single row's checkbox has been checked. But if
the user changes the checked/unchecked status of more than one, only the
first one is processed. I know that I could turn on AutoPostBack causing
each click on a checkbox to immediately post back to the server, but that is
slower and causes an unpleasant "jump" in the screen position that I wish to
avoid.

Is there a way to have the server process all the changed checkboxes on a
single postback?
 
G

Guest

Hi Sheldon,

If the step "Me.gridDoList.dataBind()" below in your code is re-binding the
GridView then you would lose all of the other checkboxes events after you
have processed the first one of them. Instead you need to move the
databinding step to another event (e.g. on submit button click event) as I do
in this sample
http://www.societopia.net/Samples/DataGrid_ChildControlsEvents.aspx (My
sample is using a datagrid in ASP.NET 1.1 but the concept is the same)
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top