473,416 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

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(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim intRowIndex As Integer

colRowsChanged = ViewState("RowsChanged")

intRowIndex = dgPhoneNumbers.DataKeys(CType(CType(sender,
Control).NamingContainer, DataGridItem).ItemIndex)

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

ViewState("RowsChanged") = colRowsChanged
End Sub

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

<asp:TextBox ID="txtDisplayName" Text='<%#
Container.DataItem("DisplayName")%>' Columns="20" MaxLength="40"
OnTextChanged="RowChanged" AutoPostBack="True" 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 1714
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(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim intRowIndex As Integer

colRowsChanged = ViewState("RowsChanged")

intRowIndex = dgPhoneNumbers.DataKeys(CType(CType(sender,
Control).NamingContainer, DataGridItem).ItemIndex)

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

ViewState("RowsChanged") = colRowsChanged
End Sub

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

<asp:TextBox ID="txtDisplayName" Text='<%#
Container.DataItem("DisplayName")%>' Columns="20" MaxLength="40"
OnTextChanged="RowChanged" AutoPostBack="True" 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(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim intRowIndex As Integer

colRowsChanged = ViewState("RowsChanged")

intRowIndex = dgPhoneNumbers.DataKeys(CType(CType(sender,
Control).NamingContainer, DataGridItem).ItemIndex)

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

ViewState("RowsChanged") = colRowsChanged
End Sub

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

<asp:TextBox ID="txtDisplayName" Text='<%#
Container.DataItem("DisplayName")%>' Columns="20" MaxLength="40"
OnTextChanged="RowChanged" AutoPostBack="True" 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(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim intRowIndex As Integer

colRowsChanged = ViewState("RowsChanged")

intRowIndex = dgPhoneNumbers.DataKeys(CType(CType(sender,
Control).NamingContainer, DataGridItem).ItemIndex)

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

ViewState("RowsChanged") = colRowsChanged
End Sub

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

<asp:TextBox ID="txtDisplayName" Text='<%#
Container.DataItem("DisplayName")%>' Columns="20" MaxLength="40"
OnTextChanged="RowChanged" AutoPostBack="True" 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(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim intRowIndex As Integer

colRowsChanged = ViewState("RowsChanged")

intRowIndex = dgPhoneNumbers.DataKeys(CType(CType(sender,
Control).NamingContainer, DataGridItem).ItemIndex)

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

ViewState("RowsChanged") = colRowsChanged
End Sub

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

<asp:TextBox ID="txtDisplayName" Text='<%#
Container.DataItem("DisplayName")%>' Columns="20" MaxLength="40"
OnTextChanged="RowChanged" AutoPostBack="True" 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***@discussions.microsoft.com> wrote in message
news:E6**********************************@microsof t.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(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> Dim intRowIndex As Integer
>
> colRowsChanged = ViewState("RowsChanged")
>
> intRowIndex = dgPhoneNumbers.DataKeys(CType(CType(sender,
> Control).NamingContainer, DataGridItem).ItemIndex)
>
> If Not colRowsChanged.Contains(intRowIndex) Then
> colRowsChanged.Add(intRowIndex)
> End If
>
> ViewState("RowsChanged") = colRowsChanged
> End Sub
>
> This Sub is called from each textbox's OnTextChanged event like this:
>
> <asp:TextBox ID="txtDisplayName" Text='<%#
> Container.DataItem("DisplayName")%>' Columns="20" MaxLength="40"
> OnTextChanged="RowChanged" AutoPostBack="True" 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***@discussions.microsoft.com> wrote in message
news:E6**********************************@microsof t.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(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> Dim intRowIndex As Integer
>
> colRowsChanged = ViewState("RowsChanged")
>
> intRowIndex = dgPhoneNumbers.DataKeys(CType(CType(sender,
> Control).NamingContainer, DataGridItem).ItemIndex)
>
> If Not colRowsChanged.Contains(intRowIndex) Then
> colRowsChanged.Add(intRowIndex)
> End If
>
> ViewState("RowsChanged") = colRowsChanged
> End Sub
>
> This Sub is called from each textbox's OnTextChanged event like this:
>
> <asp:TextBox ID="txtDisplayName" Text='<%#
> Container.DataItem("DisplayName")%>' Columns="20" MaxLength="40"
> OnTextChanged="RowChanged" AutoPostBack="True" 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
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...
4
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...
6
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...
4
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. ...
12
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...
6
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...
4
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...
9
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...
0
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. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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...
0
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,...
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...

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.