GridView1_RowUpdated problem

E

Ed Dror

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
 
S

Stan

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

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
 
E

Ed Dror

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


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

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
 
S

Stan

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

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")
 
S

Steven Cheng

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:
(e-mail address removed).


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

--------------------
From: "Ed Dror" <[email protected]>
References: <[email protected]>
 
E

Ed Dror

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,

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:
(e-mail address removed).


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

--------------------
From: "Ed Dror" <[email protected]>
References: <[email protected]>
Subject: Re: GridView1_RowUpdated problem
Date: Fri, 21 Mar 2008 13:54:07 -0700
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




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
 
S

Steven Cheng

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:
(e-mail address removed).

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


--------------------
From: "Ed Dror" <[email protected]>
References: <[email protected]>
<4e65ec7a-65dd-4654-9b28-17dbee7ce1f5@s37g2000prg.googlegroups.com>
Subject: Re: GridView1_RowUpdated problem
Date: Mon, 24 Mar 2008 12:27:07 -0700
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,

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:
(e-mail address removed).


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

--------------------
From: "Ed Dror" <[email protected]>
References: <[email protected]>
Subject: Re: GridView1_RowUpdated problem
Date: Fri, 21 Mar 2008 13:54:07 -0700
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


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

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
 
E

Ed Dror

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




"Steven Cheng" said:
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:
(e-mail address removed).

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


--------------------
From: "Ed Dror" <[email protected]>
References: <[email protected]>
<4e65ec7a-65dd-4654-9b28-17dbee7ce1f5@s37g2000prg.googlegroups.com>
Subject: Re: GridView1_RowUpdated problem
Date: Mon, 24 Mar 2008 12:27:07 -0700
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,

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:
(e-mail address removed).


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

--------------------
From: "Ed Dror" <[email protected]>
References: <[email protected]>
<4e65ec7a-65dd-4654-9b28-17dbee7ce1f5@s37g2000prg.googlegroups.com>
Subject: Re: GridView1_RowUpdated problem
Date: Fri, 21 Mar 2008 13:54:07 -0700


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


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

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
 
S

Steven Cheng

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:
(e-mail address removed).

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

--------------------
From: "Ed Dror" <[email protected]>
Subject: Re: GridView1_RowUpdated problem
Date: Tue, 25 Mar 2008 10:51:18 -0700
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




"Steven Cheng" said:
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:
(e-mail address removed).

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


--------------------
From: "Ed Dror" <[email protected]>
References: <[email protected]>
<4e65ec7a-65dd-4654-9b28-17dbee7ce1f5@s37g2000prg.googlegroups.com>
Subject: Re: GridView1_RowUpdated problem
Date: Mon, 24 Mar 2008 12:27:07 -0700
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,

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:
(e-mail address removed).


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

--------------------
From: "Ed Dror" <[email protected]>
References: <[email protected]>
<4e65ec7a-65dd-4654-9b28-17dbee7ce1f5@s37g2000prg.googlegroups.com>
Subject: Re: GridView1_RowUpdated problem
Date: Fri, 21 Mar 2008 13:54:07 -0700


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


..
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

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
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top