473,466 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Gridview Event Procedures

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?
Nov 19 '05 #1
2 2534
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/Da...olsEvents.aspx (My
sample is using a datagrid in ASP.NET 1.1 but the concept is the same)
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Sheldon Penner" wrote:
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?

Nov 19 '05 #2
Thank you for your help, Phillip. I will try your suggestion.
"Phillip Williams" wrote:
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/Da...olsEvents.aspx (My
sample is using a datagrid in ASP.NET 1.1 but the concept is the same)
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Sheldon Penner" wrote:
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?

Nov 19 '05 #3

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

Similar topics

0
by: Jim Sneeringer | last post by:
I have a GridView that loads correctly from a SQL table using a TableAdapter and stored procedures. However, when I try to delete from the GridView, I get "Procedure or Function 'EventDelete'...
4
by: anonymike | last post by:
Hello, I'm working on an ASP.NET project (VS 2005) utilizing an Oracle database backend. While I understand that Gridview's are a breeze to work with using SQL Server (hundreds of sites point...
1
by: coynej60 | last post by:
I have a GridView that is bound to a SqlDataSource that uses Stored Procedures for its Select, Insert, Update and Delete Commands. The Gridview only contains one visible column (PK Identity column...
5
by: sutphinwb | last post by:
Hi - This could be a simple question. When I relate two tables in a datasetet, how do I get that relation to show up in a GridView? The only way I've done it, is to create a separate table in the...
5
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item...
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
2
by: | last post by:
I have a gridview with a textbox in an ItemTemplate, as below. The OnTextChanged event fires okay but how do I pass a parameter to it, I get an error when I try "OnTextChanged(""SomeData"")". I...
4
by: Craig Buchanan | last post by:
I dynamically add data-bound templates to a gridview in my ascx control. while this works correctly when the gridview is databound to the datatable, i'm having issues on postback. i would like...
2
by: =?Utf-8?B?VGltIFRhZmZsaW5nZXI=?= | last post by:
I've created a DAL and can use the methods to load and manipulate data in a gridview when it is bound to an objectdatasource. But I've been told with a DAL I don't need an objectdatasource at all...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.