Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

GridView1_RowUpdated problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed Dror - 21 Mar 2008 20:38 GMT
Hi there,

I'm using ASP.NET 2.0 VB

I have a grid view based on Vendor table with SQLDatasource1
I wrote (I created a labels to hold the values from the grid +
User.Identity.Name for inserting them into a LogTable)

Protected Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles
GridView1.RowUpdated
       Try
           Me.Label1.Text = Me.GridView1.SelectedRow.Cells(1).Text
           Me.Label2.Text = Me.GridView1.SelectedRow.Cells(2).Text
           Me.Label3.Text = Me.GridView1.SelectedRow.Cells(3).Text
           Me.Label4.Text = Me.GridView1.SelectedRow.Cells(4).Text
           Me.Label5.Text = Me.GridView1.SelectedRow.Cells(5).Text
           Me.Label6.Text = Me.GridView1.SelectedRow.Cells(6).Text
           Me.Label7.Text = Me.GridView1.SelectedRow.Cells(7).Text
           Me.Label8.Text = Me.GridView1.SelectedRow.Cells(8).Text
           Me.Label9.Text = Me.GridView1.SelectedRow.Cells(9).Text
           Me.Label10.Text = Me.GridView1.SelectedRow.Cells(10).Text
           Me.Label11.Text = Me.GridView1.SelectedRow.Cells(11).Text
           Me.Label12.Text = Me.GridView1.SelectedRow.Cells(12).Text
       Catch ex As Exception
           ErrorMessage.Text = ex.Message.ToString

       End Try
   End Sub

But from some reason it show only Label1 = VendorID all the other labels are
empty

Also when is on  GridView1_Row_SelectedIndexChanged all labels are showing
values
Or on PageLoad Event all Labels are shoing values

How to make the RowUpdated Method to show all labels.

Thanks,
Ed Dror
Stan - 21 Mar 2008 21:20 GMT
> Hi there,
>
[quoted text clipped - 37 lines]
> Thanks,
> Ed Dror

Hi

The GridView rows cannot be relied upon to contain valid data during
the RowUpdated event. An SQL update command will have been executed by
the DataSource but the GridView rows are not refreshed until later.

Use the NewValues property of the GridViewUpdatedEventArgs parameter
'e' instead:

Label1.Text = e.NewValues(0)
Label2.Text = e.NewValues(1)

and so on

HTH
Ed Dror - 21 Mar 2008 21:53 GMT
Stan,

It did but I'm getting message that says:
Index was out of range. Must be non-negative and less than the size of the
collection.
Parameter name: index

Also e.NewValue(0) start with Vendor_name not vendor_Id which was Cell(1)

Thanks,
Ed Dror

On 21 Mar, 19:38, "Ed Dror" <e...@andrewlauren.com> wrote:
> Hi there,
>
[quoted text clipped - 38 lines]
> Thanks,
> Ed Dror

Hi

The GridView rows cannot be relied upon to contain valid data during
the RowUpdated event. An SQL update command will have been executed by
the DataSource but the GridView rows are not refreshed until later.

Use the NewValues property of the GridViewUpdatedEventArgs parameter
'e' instead:

Label1.Text = e.NewValues(0)
Label2.Text = e.NewValues(1)

and so on

HTH
Stan - 21 Mar 2008 23:39 GMT
> Stan,
>
[quoted text clipped - 7 lines]
> Thanks,
> Ed Dror

Ed

A better way to access the data is to use column names. I suggested a
method using index values because no column names were given. So for
example

Label1.Text = e.NewValues("vendor_id")
Steven Cheng - 24 Mar 2008 03:58 GMT
Hi Ed,

I agree with Stan that it would be better to use the "NewValues" collection
in RowUpdated event. You can loop through all updated column values through
the following code:

protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs
e)
   {
       foreach (object key in e.NewValues.Keys)
       {
           Response.Write("<br/>" + key + ": " + e.NewValues[key]);
       }
       
   }

Also, "GridView.SelectedRow" is not useful here. "SelectedRow" point to the
currently selectedrow, it is not the currently edited or updated row.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Ed Dror" <edd@andrewlauren.com>
>References: <ejhwwq4iIHA.4684@TK2MSFTNGP06.phx.gbl>
<4e65ec7a-65dd-4654-9b28-17dbee7ce1f5@s37g2000prg.googlegroups.com>
>Subject: Re: GridView1_RowUpdated problem
>Date: Fri, 21 Mar 2008 13:54:07 -0700

>Stan,
>
[quoted text clipped - 67 lines]
>
>HTH
Ed Dror - 24 Mar 2008 20:27 GMT
Steven,

All that is good but I want to include the Vendor_ID which is not showing
I tried e.NewValue("Vendor_ID") with no result (Because is PK)

when you use on selected item changed
Label1.Text = GridView1.SelectedRow.Cells(1).Text

It will show the ID but all the rest is blanc

I could let the end users click "SE:ECT" and then "EDIT" but I don't do that

Less user type is more productive for me.

Thanks,

Ed Dror

> Hi Ed,
>
[quoted text clipped - 113 lines]
>>
>>HTH
Steven Cheng - 25 Mar 2008 03:19 GMT
Thanks for your reply Ed,

Yes, using Cell[id].Text is not quite reliable since the result may change
due to the GridView column type or the current row mode.  So the problem
now is to get the primary key, have you tried using the GridView.DatdaKeys
+ GridView.EditIndex to get the key of the editing row?  e.g.

==============
  protected void GridView1_RowUpdated(object sender,
GridViewUpdatedEventArgs e)
   {
       Response.Write("<br/>NewValues: ");
       foreach (object key in e.NewValues.Keys)
       {
           Response.Write("<br/>" + key + ": " + e.NewValues[key]);
       }

       Response.Write("<br/>OldValues: ");
       foreach (object key in e.OldValues.Keys)
       {
           Response.Write("<br/>" + key + ": " + e.OldValues[key]);
       }

       Response.Write("<br/>Keys: " +
GridView1.DataKeys[GridView1.EditIndex].Value);
   }
===================

Thus, you can get all the fields' value you want.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Ed Dror" <edd@andrewlauren.com>
>References: <ejhwwq4iIHA.4684@TK2MSFTNGP06.phx.gbl>
<4e65ec7a-65dd-4654-9b28-17dbee7ce1f5@s37g2000prg.googlegroups.com>
<#caqSV5iIHA.2084@TK2MSFTNGP02.phx.gbl>
<vt0BvrVjIHA.4200@TK2MSFTNGHUB02.phx.gbl>
>Subject: Re: GridView1_RowUpdated problem
>Date: Mon, 24 Mar 2008 12:27:07 -0700

>Steven,
>
[quoted text clipped - 131 lines]
>>>
>>>HTH
Ed Dror - 25 Mar 2008 18:51 GMT
Steven,

It works...
Label1.Text = GridView1.DataKeys(GridView1.EditIndex).Value
This will give me the VendorID exactlly what I want

Thank you very mutch

Ed Dror

> Thanks for your reply Ed,
>
[quoted text clipped - 191 lines]
>>>>
>>>>HTH
Steven Cheng - 26 Mar 2008 01:56 GMT
Thanks for your reply Ed,

I'm glad that it helps you.

Have a good day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Ed Dror" <edd@andrewlauren.com>
>Subject: Re: GridView1_RowUpdated problem
>Date: Tue, 25 Mar 2008 10:51:18 -0700

>Steven,
>
[quoted text clipped - 201 lines]
>>>>>
>>>>>HTH

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.