HighTechTalks DotNet Forums  

Updating SelectedIndex after delete

ASP.net Data Grid Control microsoft.public.dotnet.framework.aspnet.datagridcontrol


Discuss Updating SelectedIndex after delete in the ASP.net Data Grid Control forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Nirmal Singh
 
Posts: n/a

Default Updating SelectedIndex after delete - 11-16-2007 , 11:40 AM






I have a delete button on my page which deletes the selected row in a
gridview.

After the deletion the selected index gets reset to -1. How can I keep the
same selected index?

Nirmal



Reply With Quote
  #2  
Old   
Teemu Keiski
 
Posts: n/a

Default Re: Updating SelectedIndex after delete - 11-18-2007 , 03:27 AM






If the index of the deleted row is greater than the selectedindex, you could
take it into a local variable before deleting (perhaps in OnRowDeleting
event), and after delete operation (in OnRowDeleted event), set it back. If
the index of the deleted row is less than or equal to selected index, you'd
need to decrement one from the index (since it's not correct anymore as it
vontains the deleted row)-->could lead to index being out of range


--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net


"Nirmal Singh" <nirmal.singh (AT) notthisbittowerhamlets (DOT) gov.uk> wrote

Quote:
I have a delete button on my page which deletes the selected row in a
gridview.

After the deletion the selected index gets reset to -1. How can I keep
the same selected index?

Nirmal




Reply With Quote
  #3  
Old   
Nirmal Singh
 
Posts: n/a

Default Re: Updating SelectedIndex after delete - 11-19-2007 , 07:00 AM



Teemu

I've added the following code in the OnRowDeleting event
DeletedRow = e.RowIndex

In the OnRowDeleted event I have the following code
RowCount = RowCount - 1
If DeletedRow = RowCount Then
grdCurrentAbsence.SelectedIndex = DeletedRow - 1
Else
grdCurrentAbsence.SelectedIndex = DeletedRow
End If

RowCount is a local varaiable holding the number of rows in the gridview.
This is still resetting the selectedIndex to -1.

What am I doing wrong?

Nirmal Singh

"Teemu Keiski" <joteke (AT) aspalliance (DOT) com> wrote

Quote:
If the index of the deleted row is greater than the selectedindex, you
could take it into a local variable before deleting (perhaps in
OnRowDeleting event), and after delete operation (in OnRowDeleted event),
set it back. If the index of the deleted row is less than or equal to
selected index, you'd need to decrement one from the index (since it's not
correct anymore as it vontains the deleted row)-->could lead to index
being out of range


--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net


"Nirmal Singh" <nirmal.singh (AT) notthisbittowerhamlets (DOT) gov.uk> wrote in
message news:OYUlj9GKIHA.1204 (AT) TK2MSFTNGP03 (DOT) phx.gbl...
I have a delete button on my page which deletes the selected row in a
gridview.

After the deletion the selected index gets reset to -1. How can I keep
the same selected index?

Nirmal






Reply With Quote
  #4  
Old   
Nirmal Singh
 
Posts: n/a

Default Re: Updating SelectedIndex after delete - 11-19-2007 , 07:17 AM



Got it.

The OnRowDeleting event should be for the gridview but the OnRowDeleted
event should be for the datasource.

It's working as expected now.

Nirmal

"Nirmal Singh" <nirmal.singh (AT) notthisbittowerhamlets (DOT) gov.uk> wrote

Quote:
Teemu

I've added the following code in the OnRowDeleting event
DeletedRow = e.RowIndex

In the OnRowDeleted event I have the following code
RowCount = RowCount - 1
If DeletedRow = RowCount Then
grdCurrentAbsence.SelectedIndex = DeletedRow - 1
Else
grdCurrentAbsence.SelectedIndex = DeletedRow
End If

RowCount is a local varaiable holding the number of rows in the gridview.
This is still resetting the selectedIndex to -1.

What am I doing wrong?

Nirmal Singh

"Teemu Keiski" <joteke (AT) aspalliance (DOT) com> wrote in message
news:eNBonzbKIHA.4688 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
If the index of the deleted row is greater than the selectedindex, you
could take it into a local variable before deleting (perhaps in
OnRowDeleting event), and after delete operation (in OnRowDeleted event),
set it back. If the index of the deleted row is less than or equal to
selected index, you'd need to decrement one from the index (since it's
not correct anymore as it vontains the deleted row)-->could lead to index
being out of range


--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net


"Nirmal Singh" <nirmal.singh (AT) notthisbittowerhamlets (DOT) gov.uk> wrote in
message news:OYUlj9GKIHA.1204 (AT) TK2MSFTNGP03 (DOT) phx.gbl...
I have a delete button on my page which deletes the selected row in a
gridview.

After the deletion the selected index gets reset to -1. How can I keep
the same selected index?

Nirmal








Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.