|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Updating SelectedIndex after deleteI 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 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 Show quoteHide quote "Nirmal Singh" <nirmal.si***@notthisbittowerhamlets.gov.uk> wrote in message news:OYUlj9GKIHA.1204@TK2MSFTNGP03.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 > 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 Show quoteHide quote "Teemu Keiski" <jot***@aspalliance.com> wrote in message news:eNBonzbKIHA.4688@TK2MSFTNGP06.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.si***@notthisbittowerhamlets.gov.uk> wrote in > message news:OYUlj9GKIHA.1204@TK2MSFTNGP03.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 >> > > 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 Show quoteHide quote "Nirmal Singh" <nirmal.si***@notthisbittowerhamlets.gov.uk> wrote in message news:eBnE9OqKIHA.2432@TK2MSFTNGP04.phx.gbl... > 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" <jot***@aspalliance.com> wrote in message > news:eNBonzbKIHA.4688@TK2MSFTNGP06.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.si***@notthisbittowerhamlets.gov.uk> wrote in >> message news:OYUlj9GKIHA.1204@TK2MSFTNGP03.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 >>> >> >> > >
Reload/refresh data in datagrid
GridView is making two of each column wrap text in datagrid cell wrapping text in datagrid Making an entire column visible/not visible. Programattically setting gridview to edit mode GridView - Hyperlink Editing/Deleting/Inserting Records using ASPxGridView Hiding grid columns based on some value in row DataView Borders |
|||||||||||||||||||||||