473,651 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET question about datagrid row changes

I have a page that shows some data in a datagrid. All rows are updateable
and then the changes are saved by hitting the "Save Changes" button. It is
not a row by row save. All edits are made and then all altered rows are
saved at once. It can be big, so I only want to save the ones that have
changed. I'm keeping track of the changed rows in ViewState with this code:

Protected Sub RowChanged(ByVa l sender As System.Object, ByVal e As
System.EventArg s)
Dim intRowIndex As Integer

colRowsChanged = ViewState("Rows Changed")

intRowIndex = dgPhoneNumbers. DataKeys(CType( CType(sender,
Control).Naming Container, DataGridItem).I temIndex)

If Not colRowsChanged. Contains(intRow Index) Then
colRowsChanged. Add(intRowIndex )
End If

ViewState("Rows Changed") = colRowsChanged
End Sub

This Sub is called from each textbox's OnTextChanged event like this:

<asp:TextBox ID="txtDisplayN ame" Text='<%#
Container.DataI tem("DisplayNam e")%>' Columns="20" MaxLength="40"
OnTextChanged=" RowChanged" AutoPostBack="T rue" runat="server" />

It all works fine, except that the RowChanged sub only fires when the row
change is followed by a tab or specifically clicking away from the textbox.
This causes a problem if someone changes a few rows and directly clicks "Save
Changes" without purposefully clicking away from the textbox first. Most
users are going to just click "Save Changes" after making the last change, so
this is causing problems.

Is there another way to fire this Sub? Or other suggestions.
Thanks.
Nov 19 '05 #1
6 1734
Use a javascript function call delay and then from javascript call the click
event

"lanem" wrote:
I have a page that shows some data in a datagrid. All rows are updateable
and then the changes are saved by hitting the "Save Changes" button. It is
not a row by row save. All edits are made and then all altered rows are
saved at once. It can be big, so I only want to save the ones that have
changed. I'm keeping track of the changed rows in ViewState with this code:

Protected Sub RowChanged(ByVa l sender As System.Object, ByVal e As
System.EventArg s)
Dim intRowIndex As Integer

colRowsChanged = ViewState("Rows Changed")

intRowIndex = dgPhoneNumbers. DataKeys(CType( CType(sender,
Control).Naming Container, DataGridItem).I temIndex)

If Not colRowsChanged. Contains(intRow Index) Then
colRowsChanged. Add(intRowIndex )
End If

ViewState("Rows Changed") = colRowsChanged
End Sub

This Sub is called from each textbox's OnTextChanged event like this:

<asp:TextBox ID="txtDisplayN ame" Text='<%#
Container.DataI tem("DisplayNam e")%>' Columns="20" MaxLength="40"
OnTextChanged=" RowChanged" AutoPostBack="T rue" runat="server" />

It all works fine, except that the RowChanged sub only fires when the row
change is followed by a tab or specifically clicking away from the textbox.
This causes a problem if someone changes a few rows and directly clicks "Save
Changes" without purposefully clicking away from the textbox first. Most
users are going to just click "Save Changes" after making the last change, so
this is causing problems.

Is there another way to fire this Sub? Or other suggestions.
Thanks.

Nov 19 '05 #2
Thanks. How do you call the click event from JavaScript?

"Sérgio" wrote:
Use a javascript function call delay and then from javascript call the click
event

"lanem" wrote:
I have a page that shows some data in a datagrid. All rows are updateable
and then the changes are saved by hitting the "Save Changes" button. It is
not a row by row save. All edits are made and then all altered rows are
saved at once. It can be big, so I only want to save the ones that have
changed. I'm keeping track of the changed rows in ViewState with this code:

Protected Sub RowChanged(ByVa l sender As System.Object, ByVal e As
System.EventArg s)
Dim intRowIndex As Integer

colRowsChanged = ViewState("Rows Changed")

intRowIndex = dgPhoneNumbers. DataKeys(CType( CType(sender,
Control).Naming Container, DataGridItem).I temIndex)

If Not colRowsChanged. Contains(intRow Index) Then
colRowsChanged. Add(intRowIndex )
End If

ViewState("Rows Changed") = colRowsChanged
End Sub

This Sub is called from each textbox's OnTextChanged event like this:

<asp:TextBox ID="txtDisplayN ame" Text='<%#
Container.DataI tem("DisplayNam e")%>' Columns="20" MaxLength="40"
OnTextChanged=" RowChanged" AutoPostBack="T rue" runat="server" />

It all works fine, except that the RowChanged sub only fires when the row
change is followed by a tab or specifically clicking away from the textbox.
This causes a problem if someone changes a few rows and directly clicks "Save
Changes" without purposefully clicking away from the textbox first. Most
users are going to just click "Save Changes" after making the last change, so
this is causing problems.

Is there another way to fire this Sub? Or other suggestions.
Thanks.

Nov 19 '05 #3
window.document .getElementById ("buttonName"). click();

"lanem" wrote:
Thanks. How do you call the click event from JavaScript?

"Sérgio" wrote:
Use a javascript function call delay and then from javascript call the click
event

"lanem" wrote:
I have a page that shows some data in a datagrid. All rows are updateable
and then the changes are saved by hitting the "Save Changes" button. It is
not a row by row save. All edits are made and then all altered rows are
saved at once. It can be big, so I only want to save the ones that have
changed. I'm keeping track of the changed rows in ViewState with this code:

Protected Sub RowChanged(ByVa l sender As System.Object, ByVal e As
System.EventArg s)
Dim intRowIndex As Integer

colRowsChanged = ViewState("Rows Changed")

intRowIndex = dgPhoneNumbers. DataKeys(CType( CType(sender,
Control).Naming Container, DataGridItem).I temIndex)

If Not colRowsChanged. Contains(intRow Index) Then
colRowsChanged. Add(intRowIndex )
End If

ViewState("Rows Changed") = colRowsChanged
End Sub

This Sub is called from each textbox's OnTextChanged event like this:

<asp:TextBox ID="txtDisplayN ame" Text='<%#
Container.DataI tem("DisplayNam e")%>' Columns="20" MaxLength="40"
OnTextChanged=" RowChanged" AutoPostBack="T rue" runat="server" />

It all works fine, except that the RowChanged sub only fires when the row
change is followed by a tab or specifically clicking away from the textbox.
This causes a problem if someone changes a few rows and directly clicks "Save
Changes" without purposefully clicking away from the textbox first. Most
users are going to just click "Save Changes" after making the last change, so
this is causing problems.

Is there another way to fire this Sub? Or other suggestions.
Thanks.

Nov 19 '05 #4
I have been looking into trying the time delay, but I don't really see how
that is going to help. When the person clicks the "Save Changes" button
after changing that last row, the RowChanged function fires and the click
event doesn't fire, b/c the page has posted back for the RowChanged function.
Then, the user has to hit "Save Changes" again. A time delay on the client
side will not matter once the page has posted back.
Thanks.

"Sérgio" wrote:
Use a javascript function call delay and then from javascript call the click
event

"lanem" wrote:
I have a page that shows some data in a datagrid. All rows are updateable
and then the changes are saved by hitting the "Save Changes" button. It is
not a row by row save. All edits are made and then all altered rows are
saved at once. It can be big, so I only want to save the ones that have
changed. I'm keeping track of the changed rows in ViewState with this code:

Protected Sub RowChanged(ByVa l sender As System.Object, ByVal e As
System.EventArg s)
Dim intRowIndex As Integer

colRowsChanged = ViewState("Rows Changed")

intRowIndex = dgPhoneNumbers. DataKeys(CType( CType(sender,
Control).Naming Container, DataGridItem).I temIndex)

If Not colRowsChanged. Contains(intRow Index) Then
colRowsChanged. Add(intRowIndex )
End If

ViewState("Rows Changed") = colRowsChanged
End Sub

This Sub is called from each textbox's OnTextChanged event like this:

<asp:TextBox ID="txtDisplayN ame" Text='<%#
Container.DataI tem("DisplayNam e")%>' Columns="20" MaxLength="40"
OnTextChanged=" RowChanged" AutoPostBack="T rue" runat="server" />

It all works fine, except that the RowChanged sub only fires when the row
change is followed by a tab or specifically clicking away from the textbox.
This causes a problem if someone changes a few rows and directly clicks "Save
Changes" without purposefully clicking away from the textbox first. Most
users are going to just click "Save Changes" after making the last change, so
this is causing problems.

Is there another way to fire this Sub? Or other suggestions.
Thanks.

Nov 19 '05 #5
I think your best bet would be to fire a client side event prior to the
post-back when clicking on the "Save Changes" button.

On your server-side button, in the code-behind you could add an "onClick"
attribute to the button, so that when it's clicked it will run the specified
javascript function prior to posting. In the script you can set focus
somewhere else, or take the item out of "edit mode".

Hope that helps.

-Darrin
"lanem" <la***@discussi ons.microsoft.c om> wrote in message
news:E6******** *************** ***********@mic rosoft.com...
I have been looking into trying the time delay, but I don't really see how
that is going to help. When the person clicks the "Save Changes" button
after changing that last row, the RowChanged function fires and the click
event doesn't fire, b/c the page has posted back for the RowChanged
function.
Then, the user has to hit "Save Changes" again. A time delay on the
client
side will not matter once the page has posted back.
Thanks.

"Sérgio" wrote:
Use a javascript function call delay and then from javascript call the
click
event

"lanem" wrote:
> I have a page that shows some data in a datagrid. All rows are
> updateable
> and then the changes are saved by hitting the "Save Changes" button.
> It is
> not a row by row save. All edits are made and then all altered rows
> are
> saved at once. It can be big, so I only want to save the ones that
> have
> changed. I'm keeping track of the changed rows in ViewState with this
> code:
>
> Protected Sub RowChanged(ByVa l sender As System.Object, ByVal e As
> System.EventArg s)
> Dim intRowIndex As Integer
>
> colRowsChanged = ViewState("Rows Changed")
>
> intRowIndex = dgPhoneNumbers. DataKeys(CType( CType(sender,
> Control).Naming Container, DataGridItem).I temIndex)
>
> If Not colRowsChanged. Contains(intRow Index) Then
> colRowsChanged. Add(intRowIndex )
> End If
>
> ViewState("Rows Changed") = colRowsChanged
> End Sub
>
> This Sub is called from each textbox's OnTextChanged event like this:
>
> <asp:TextBox ID="txtDisplayN ame" Text='<%#
> Container.DataI tem("DisplayNam e")%>' Columns="20" MaxLength="40"
> OnTextChanged=" RowChanged" AutoPostBack="T rue" runat="server" />
>
> It all works fine, except that the RowChanged sub only fires when the
> row
> change is followed by a tab or specifically clicking away from the
> textbox.
> This causes a problem if someone changes a few rows and directly clicks
> "Save
> Changes" without purposefully clicking away from the textbox first.
> Most
> users are going to just click "Save Changes" after making the last
> change, so
> this is causing problems.
>
> Is there another way to fire this Sub? Or other suggestions.
> Thanks.

Nov 19 '05 #6
I use two buttons , the first is visible and is html button that call client
side function, and the second is a server button that is hidden and is call
in the client side function with the delay function. when the postback is
call the focus the was in the text field have change to the html button and
the event onrowchange is fired.

I hope that helps

Sérgio

"Darrin J. Olson" wrote:
I think your best bet would be to fire a client side event prior to the
post-back when clicking on the "Save Changes" button.

On your server-side button, in the code-behind you could add an "onClick"
attribute to the button, so that when it's clicked it will run the specified
javascript function prior to posting. In the script you can set focus
somewhere else, or take the item out of "edit mode".

Hope that helps.

-Darrin
"lanem" <la***@discussi ons.microsoft.c om> wrote in message
news:E6******** *************** ***********@mic rosoft.com...
I have been looking into trying the time delay, but I don't really see how
that is going to help. When the person clicks the "Save Changes" button
after changing that last row, the RowChanged function fires and the click
event doesn't fire, b/c the page has posted back for the RowChanged
function.
Then, the user has to hit "Save Changes" again. A time delay on the
client
side will not matter once the page has posted back.
Thanks.

"Sérgio" wrote:
Use a javascript function call delay and then from javascript call the
click
event

"lanem" wrote:

> I have a page that shows some data in a datagrid. All rows are
> updateable
> and then the changes are saved by hitting the "Save Changes" button.
> It is
> not a row by row save. All edits are made and then all altered rows
> are
> saved at once. It can be big, so I only want to save the ones that
> have
> changed. I'm keeping track of the changed rows in ViewState with this
> code:
>
> Protected Sub RowChanged(ByVa l sender As System.Object, ByVal e As
> System.EventArg s)
> Dim intRowIndex As Integer
>
> colRowsChanged = ViewState("Rows Changed")
>
> intRowIndex = dgPhoneNumbers. DataKeys(CType( CType(sender,
> Control).Naming Container, DataGridItem).I temIndex)
>
> If Not colRowsChanged. Contains(intRow Index) Then
> colRowsChanged. Add(intRowIndex )
> End If
>
> ViewState("Rows Changed") = colRowsChanged
> End Sub
>
> This Sub is called from each textbox's OnTextChanged event like this:
>
> <asp:TextBox ID="txtDisplayN ame" Text='<%#
> Container.DataI tem("DisplayNam e")%>' Columns="20" MaxLength="40"
> OnTextChanged=" RowChanged" AutoPostBack="T rue" runat="server" />
>
> It all works fine, except that the RowChanged sub only fires when the
> row
> change is followed by a tab or specifically clicking away from the
> textbox.
> This causes a problem if someone changes a few rows and directly clicks
> "Save
> Changes" without purposefully clicking away from the textbox first.
> Most
> users are going to just click "Save Changes" after making the last
> change, so
> this is causing problems.
>
> Is there another way to fire this Sub? Or other suggestions.
> Thanks.


Nov 19 '05 #7

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

Similar topics

6
1631
by: BFX | last post by:
Hi All, I have datagrid with binding on dataset this.grdMachineType.DataMember = "MachineTypes"; this.grdMachineType.DataSource = this.dsMachineTypes; After append new row in datagrid i call this
4
2408
by: Sangeetha. | last post by:
I have a datagrid with just one row. When I edit the contents of the datagrid and click on Save button (somewhere else in the form), the changes are lost. However, if I click TAB from the editable column of the datagrid, the changes are saved. Is there a way to save the changes without clicking TAB button ?
6
1706
by: BBFrost | last post by:
I'm using Net 1.1 (2003) SP1 & Windows 2000 Here's the issue ... Rows 12 thru 24 are selected in a datagrid. The user now unselects rows 12 thru 24 and selects rows 45 thru 70 ??? How can I tell that the user has reselected a different set of rows in a datagrid.
4
5350
by: Glenn Owens | last post by:
I have a DataGrid web control which I've dynamically populated with template columns to be used for bulk-editting. Generally, all of the columns are textbox and/or dropdownlist child controls. Currently everything is working. I can find the updated rows/columns by parsing the posted data collection against the DataGrid DataSource. However, when there is a large amount of DataGridItems (rows) the update processing can take a while. ...
12
1996
by: Daniel Walzenbach | last post by:
Hi, I want to display a Label in a DataGrid according to some condition. I therefore check whether the condition is true in the ItemDateBound EventHandler of the DataGrid. Unfortunately the conversion is extremely costly in performance. Does anybody know how I could set the label (of the whole content of the TableCell) to .Visible = False without converting e.Item.Controls(2) to a System.Web.UI.WebControls.Label?
6
1220
by: Joe | last post by:
Hi, I have a MS Access DB in which a record has just too many fields to be able to allow users to do inline editing in a datagrid. So I want to display as First Name: Text box where first name is displayed and can be edited. Last Name: Text box where last name is displayed and can be edited. At the end of this list, I want to have two buttons, update and cancel.
4
7365
by: Suzanne | last post by:
Hi all, I'm having problems with datagrids and the currentcellchanged event. My problem is this: I have a datagrid on a form, if the user changes the text in a cell on the datagrid then tries to close the form via a button on the toolbar (with going to another cell in the datagrid)I want to be able to popup a messagebox to the user asking them if they want to keep their changes. At the momment I'm accomplishing this by a property that...
9
2713
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
0
1127
by: gtyler | last post by:
When you make changes to a DataGrid a picture of a Pencil appears on the right hand side. As I understand it, the DataSource is not updated until you move off that row and the Pencil disappears. If one of my users were to close the form without remembering to press the “Update Database” button then the changes would be lost. So I wrote a procedure for the On Closing Event that checks for Modified rows, and if there are it prompts the user to...
0
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7296
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
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 we have to send another system
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.