473,387 Members | 1,760 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,387 software developers and data experts.

Persisting the currently selected row on a GridView

I have a GridView bound to an ObjectDataSource. I have a Button that calls
GridView.DataBind. I want the row that is selected before the DataBind to
still be selected afterwards.

This happens automatically if the data doesn't change. But if records have
been added or deleted then it looks as if some code is necessary: I've done
this by using GridView.SelectedValue to get the key value of the currently
selected Row and then by itterating through the DataKeys collection (after
the DataBind has completed) I can work out the RowIndex of the Row that has
the same key value. There's some more code to adjust for the GridView's
PageIndex but otherwise this works.

But what I've not been able to do is adjust for the occassions when the row
that I'm hoping to select is no longer on the same PageIndex. I've got close
by handling the ObjectDataSource_Selected event and I can now predict which
page the row will be on (although I've not tested wither sort orders effect
this). But how do I then make the GridView display the correct page?

Hope you can help.
Jan 19 '06 #1
5 4815
Hi Richard,

Welcome to ASPNET newsgroup.
Regarding on the GridView control's row selection, it is a very simple
implementation which dosn't quite associated with the underlying
datasource, the SelectedIndex only range in the current displayed page of
data. So when our page size is set to 5, the available selectedIndex is
from 0 to 4....

So when there is changes made on the underlying datasource or page index
changed... If we still want to keep the original selected dataitem, I'm
afraid we have to manually calculate the index of that record on the
certain page (according to total records count, page size), then set the
proper page index and selected index....

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Thread-Topic: Persisting the currently selected row on a GridView
| thread-index: AcYdOIdSa2b3anygQnilL8UCN+aWPQ==
| X-WBNR-Posting-Host: 193.130.25.218
| From: "=?Utf-8?B?RGljaw==?=" <Ri***********@nospam.nospam>
| Subject: Persisting the currently selected row on a GridView
| Date: Thu, 19 Jan 2006 12:40:05 -0800
| Lines: 19
| Message-ID: <61**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:372201
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I have a GridView bound to an ObjectDataSource. I have a Button that
calls
| GridView.DataBind. I want the row that is selected before the DataBind to
| still be selected afterwards.
|
| This happens automatically if the data doesn't change. But if records
have
| been added or deleted then it looks as if some code is necessary: I've
done
| this by using GridView.SelectedValue to get the key value of the
currently
| selected Row and then by itterating through the DataKeys collection
(after
| the DataBind has completed) I can work out the RowIndex of the Row that
has
| the same key value. There's some more code to adjust for the GridView's
| PageIndex but otherwise this works.
|
| But what I've not been able to do is adjust for the occassions when the
row
| that I'm hoping to select is no longer on the same PageIndex. I've got
close
| by handling the ObjectDataSource_Selected event and I can now predict
which
| page the row will be on (although I've not tested wither sort orders
effect
| this). But how do I then make the GridView display the correct page?
|
| Hope you can help.
|

Jan 20 '06 #2
Thanks for the reply. I'm almost certain I understood what you wrote. I think
the (only?) place to calculate the page and index that the record will be on
is the ObjectDataSource_Selected event because, as far as I can see, this is
the only event that has access to the underlying datasource. But if I set
GridView.PageIndex from this event it causes the control to repeat the call
to the database, i.e. the series of events is thus:

User selectes to "Refresh Bound Controls"...
1. ObjectDataSource_Selecting
2. ObjectDataSource_Selected
2.1 Calculate and set the required page i.e. GridView.PageIndex = n
3. GridView_DataBinding
4. GridView_DataBound
5. ObjectDataSource_Selecting
6. ObjectDataSource_Selected
7. GridView_DataBinding
8. GridView_DataBound

I think that events 5 to 8 are caused by changing the GridView.PageIndex in
2.1. The events to not re-fire the second time GridView.PageIndex is set,
presumably because the PageIndex is already the required value.

The key thing here is that the database is called twice (and maybe the page
is rendered on the BRowser twice?) and is thus an overhead that we should
avoid. Can you help me with a better solution?
"Steven Cheng[MSFT]" wrote:
Hi Richard,

Welcome to ASPNET newsgroup.
Regarding on the GridView control's row selection, it is a very simple
implementation which dosn't quite associated with the underlying
datasource, the SelectedIndex only range in the current displayed page of
data. So when our page size is set to 5, the available selectedIndex is
from 0 to 4....

So when there is changes made on the underlying datasource or page index
changed... If we still want to keep the original selected dataitem, I'm
afraid we have to manually calculate the index of that record on the
certain page (according to total records count, page size), then set the
proper page index and selected index....

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Thread-Topic: Persisting the currently selected row on a GridView
| thread-index: AcYdOIdSa2b3anygQnilL8UCN+aWPQ==
| X-WBNR-Posting-Host: 193.130.25.218
| From: "=?Utf-8?B?RGljaw==?=" <Ri***********@nospam.nospam>
| Subject: Persisting the currently selected row on a GridView
| Date: Thu, 19 Jan 2006 12:40:05 -0800
| Lines: 19
| Message-ID: <61**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:372201
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I have a GridView bound to an ObjectDataSource. I have a Button that
calls
| GridView.DataBind. I want the row that is selected before the DataBind to
| still be selected afterwards.
|
| This happens automatically if the data doesn't change. But if records
have
| been added or deleted then it looks as if some code is necessary: I've
done
| this by using GridView.SelectedValue to get the key value of the
currently
| selected Row and then by itterating through the DataKeys collection
(after
| the DataBind has completed) I can work out the RowIndex of the Row that
has
| the same key value. There's some more code to adjust for the GridView's
| PageIndex but otherwise this works.
|
| But what I've not been able to do is adjust for the occassions when the
row
| that I'm hoping to select is no longer on the same PageIndex. I've got
close
| by handling the ObjectDataSource_Selected event and I can now predict
which
| page the row will be on (although I've not tested wither sort orders
effect
| this). But how do I then make the GridView display the correct page?
|
| Hope you can help.
|

Jan 20 '06 #3
Thanks for your response Richard,

Yes, changing the Page will cause the GridView to rebind the data from
DataSource control again.... I'm afraid this is not avoidable if the
original selected data item is not on the current Page( or in anothe word,
we have to change page index .....). Also, call the DataBind method twice
won't make the GridView be rendered twice on the page. And the drawback is
that the database will be queried twice (if not using cache) as you
mentioned....

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: Persisting the currently selected row on a GridView
| thread-index: AcYdoU0ECG96QNn/Q3GGTxtnEgBdwQ==
| X-WBNR-Posting-Host: 86.137.242.173
| From: "=?Utf-8?B?RGljaw==?=" <Ri***********@nospam.nospam>
| References: <61**********************************@microsoft.co m>
<c8**************@TK2MSFTNGXA02.phx.gbl>
| Subject: RE: Persisting the currently selected row on a GridView
| Date: Fri, 20 Jan 2006 01:10:04 -0800
| Lines: 112
| Message-ID: <F6**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:372333
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks for the reply. I'm almost certain I understood what you wrote. I
think
| the (only?) place to calculate the page and index that the record will be
on
| is the ObjectDataSource_Selected event because, as far as I can see, this
is
| the only event that has access to the underlying datasource. But if I set
| GridView.PageIndex from this event it causes the control to repeat the
call
| to the database, i.e. the series of events is thus:
|
| User selectes to "Refresh Bound Controls"...
| 1. ObjectDataSource_Selecting
| 2. ObjectDataSource_Selected
| 2.1 Calculate and set the required page i.e. GridView.PageIndex = n
| 3. GridView_DataBinding
| 4. GridView_DataBound
| 5. ObjectDataSource_Selecting
| 6. ObjectDataSource_Selected
| 7. GridView_DataBinding
| 8. GridView_DataBound
|
| I think that events 5 to 8 are caused by changing the GridView.PageIndex
in
| 2.1. The events to not re-fire the second time GridView.PageIndex is set,
| presumably because the PageIndex is already the required value.
|
| The key thing here is that the database is called twice (and maybe the
page
| is rendered on the BRowser twice?) and is thus an overhead that we should
| avoid. Can you help me with a better solution?
|
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi Richard,
| >
| > Welcome to ASPNET newsgroup.
| > Regarding on the GridView control's row selection, it is a very simple
| > implementation which dosn't quite associated with the underlying
| > datasource, the SelectedIndex only range in the current displayed page
of
| > data. So when our page size is set to 5, the available selectedIndex is
| > from 0 to 4....
| >
| > So when there is changes made on the underlying datasource or page
index
| > changed... If we still want to keep the original selected dataitem, I'm
| > afraid we have to manually calculate the index of that record on the
| > certain page (according to total records count, page size), then set
the
| > proper page index and selected index....
| >
| > Regards,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | Thread-Topic: Persisting the currently selected row on a GridView
| > | thread-index: AcYdOIdSa2b3anygQnilL8UCN+aWPQ==
| > | X-WBNR-Posting-Host: 193.130.25.218
| > | From: "=?Utf-8?B?RGljaw==?=" <Ri***********@nospam.nospam>
| > | Subject: Persisting the currently selected row on a GridView
| > | Date: Thu, 19 Jan 2006 12:40:05 -0800
| > | Lines: 19
| > | Message-ID: <61**********************************@microsoft.co m>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:372201
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | I have a GridView bound to an ObjectDataSource. I have a Button that
| > calls
| > | GridView.DataBind. I want the row that is selected before the
DataBind to
| > | still be selected afterwards.
| > |
| > | This happens automatically if the data doesn't change. But if records
| > have
| > | been added or deleted then it looks as if some code is necessary:
I've
| > done
| > | this by using GridView.SelectedValue to get the key value of the
| > currently
| > | selected Row and then by itterating through the DataKeys collection
| > (after
| > | the DataBind has completed) I can work out the RowIndex of the Row
that
| > has
| > | the same key value. There's some more code to adjust for the
GridView's
| > | PageIndex but otherwise this works.
| > |
| > | But what I've not been able to do is adjust for the occassions when
the
| > row
| > | that I'm hoping to select is no longer on the same PageIndex. I've
got
| > close
| > | by handling the ObjectDataSource_Selected event and I can now predict
| > which
| > | page the row will be on (although I've not tested wither sort orders
| > effect
| > | this). But how do I then make the GridView display the correct page?
| > |
| > | Hope you can help.
| > |
| >
| >
|

Jan 23 '06 #4
Thanks for your reply. Over the weekend I learnt about server-side sorting
and paging and this eventually leads to a perfectly elegent solution for
working out which page the required record will be on.

"Steven Cheng[MSFT]" wrote:
Thanks for your response Richard,

Yes, changing the Page will cause the GridView to rebind the data from
DataSource control again.... I'm afraid this is not avoidable if the
original selected data item is not on the current Page( or in anothe word,
we have to change page index .....). Also, call the DataBind method twice
won't make the GridView be rendered twice on the page. And the drawback is
that the database will be queried twice (if not using cache) as you
mentioned....

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: Persisting the currently selected row on a GridView
| thread-index: AcYdoU0ECG96QNn/Q3GGTxtnEgBdwQ==
| X-WBNR-Posting-Host: 86.137.242.173
| From: "=?Utf-8?B?RGljaw==?=" <Ri***********@nospam.nospam>
| References: <61**********************************@microsoft.co m>
<c8**************@TK2MSFTNGXA02.phx.gbl>
| Subject: RE: Persisting the currently selected row on a GridView
| Date: Fri, 20 Jan 2006 01:10:04 -0800
| Lines: 112
| Message-ID: <F6**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:372333
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks for the reply. I'm almost certain I understood what you wrote. I
think
| the (only?) place to calculate the page and index that the record will be
on
| is the ObjectDataSource_Selected event because, as far as I can see, this
is
| the only event that has access to the underlying datasource. But if I set
| GridView.PageIndex from this event it causes the control to repeat the
call
| to the database, i.e. the series of events is thus:
|
| User selectes to "Refresh Bound Controls"...
| 1. ObjectDataSource_Selecting
| 2. ObjectDataSource_Selected
| 2.1 Calculate and set the required page i.e. GridView.PageIndex = n
| 3. GridView_DataBinding
| 4. GridView_DataBound
| 5. ObjectDataSource_Selecting
| 6. ObjectDataSource_Selected
| 7. GridView_DataBinding
| 8. GridView_DataBound
|
| I think that events 5 to 8 are caused by changing the GridView.PageIndex
in
| 2.1. The events to not re-fire the second time GridView.PageIndex is set,
| presumably because the PageIndex is already the required value.
|
| The key thing here is that the database is called twice (and maybe the
page
| is rendered on the BRowser twice?) and is thus an overhead that we should
| avoid. Can you help me with a better solution?
|
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi Richard,
| >
| > Welcome to ASPNET newsgroup.
| > Regarding on the GridView control's row selection, it is a very simple
| > implementation which dosn't quite associated with the underlying
| > datasource, the SelectedIndex only range in the current displayed page
of
| > data. So when our page size is set to 5, the available selectedIndex is
| > from 0 to 4....
| >
| > So when there is changes made on the underlying datasource or page
index
| > changed... If we still want to keep the original selected dataitem, I'm
| > afraid we have to manually calculate the index of that record on the
| > certain page (according to total records count, page size), then set
the
| > proper page index and selected index....
| >
| > Regards,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | Thread-Topic: Persisting the currently selected row on a GridView
| > | thread-index: AcYdOIdSa2b3anygQnilL8UCN+aWPQ==
| > | X-WBNR-Posting-Host: 193.130.25.218
| > | From: "=?Utf-8?B?RGljaw==?=" <Ri***********@nospam.nospam>
| > | Subject: Persisting the currently selected row on a GridView
| > | Date: Thu, 19 Jan 2006 12:40:05 -0800
| > | Lines: 19
| > | Message-ID: <61**********************************@microsoft.co m>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:372201
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | I have a GridView bound to an ObjectDataSource. I have a Button that
| > calls
| > | GridView.DataBind. I want the row that is selected before the
DataBind to
| > | still be selected afterwards.
| > |
| > | This happens automatically if the data doesn't change. But if records
| > have
| > | been added or deleted then it looks as if some code is necessary:
I've
| > done
| > | this by using GridView.SelectedValue to get the key value of the
| > currently
| > | selected Row and then by itterating through the DataKeys collection
| > (after
| > | the DataBind has completed) I can work out the RowIndex of the Row
that
| > has
| > | the same key value. There's some more code to adjust for the
GridView's
| > | PageIndex but otherwise this works.
| > |
| > | But what I've not been able to do is adjust for the occassions when
the
| > row
| > | that I'm hoping to select is no longer on the same PageIndex. I've
got
| > close
| > | by handling the ObjectDataSource_Selected event and I can now predict
| > which
| > | page the row will be on (although I've not tested wither sort orders
| > effect
| > | this). But how do I then make the GridView display the correct page?
| > |
| > | Hope you can help.
| > |
| >
| >
|

Jan 23 '06 #5
Thanks for your quick response.

Glad that you've also found your solution on this.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: Persisting the currently selected row on a GridView
| thread-index: AcYgIfQ1A6LagImOS0eMeHlP0pDDSg==
| X-WBNR-Posting-Host: 193.130.25.218
| From: "=?Utf-8?B?RGljaw==?=" <Ri***********@nospam.nospam>
| References: <61**********************************@microsoft.co m>
<c8**************@TK2MSFTNGXA02.phx.gbl>
<F6**********************************@microsoft.co m>
<Rc**************@TK2MSFTNGXA02.phx.gbl>
| Subject: RE: Persisting the currently selected row on a GridView
| Date: Mon, 23 Jan 2006 05:36:02 -0800
| Lines: 183
| Message-ID: <AF**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:372863
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks for your reply. Over the weekend I learnt about server-side
sorting
| and paging and this eventually leads to a perfectly elegent solution for
| working out which page the required record will be on.
|
| "Steven Cheng[MSFT]" wrote:
|
| > Thanks for your response Richard,
| >
| > Yes, changing the Page will cause the GridView to rebind the data from
| > DataSource control again.... I'm afraid this is not avoidable if the
| > original selected data item is not on the current Page( or in anothe
word,
| > we have to change page index .....). Also, call the DataBind method
twice
| > won't make the GridView be rendered twice on the page. And the drawback
is
| > that the database will be queried twice (if not using cache) as you
| > mentioned....
| >
| > Regards,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| > --------------------
| > | Thread-Topic: Persisting the currently selected row on a GridView
| > | thread-index: AcYdoU0ECG96QNn/Q3GGTxtnEgBdwQ==
| > | X-WBNR-Posting-Host: 86.137.242.173
| > | From: "=?Utf-8?B?RGljaw==?=" <Ri***********@nospam.nospam>
| > | References: <61**********************************@microsoft.co m>
| > <c8**************@TK2MSFTNGXA02.phx.gbl>
| > | Subject: RE: Persisting the currently selected row on a GridView
| > | Date: Fri, 20 Jan 2006 01:10:04 -0800
| > | Lines: 112
| > | Message-ID: <F6**********************************@microsoft.co m>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:372333
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Thanks for the reply. I'm almost certain I understood what you wrote.
I
| > think
| > | the (only?) place to calculate the page and index that the record
will be
| > on
| > | is the ObjectDataSource_Selected event because, as far as I can see,
this
| > is
| > | the only event that has access to the underlying datasource. But if I
set
| > | GridView.PageIndex from this event it causes the control to repeat
the
| > call
| > | to the database, i.e. the series of events is thus:
| > |
| > | User selectes to "Refresh Bound Controls"...
| > | 1. ObjectDataSource_Selecting
| > | 2. ObjectDataSource_Selected
| > | 2.1 Calculate and set the required page i.e. GridView.PageIndex =
n
| > | 3. GridView_DataBinding
| > | 4. GridView_DataBound
| > | 5. ObjectDataSource_Selecting
| > | 6. ObjectDataSource_Selected
| > | 7. GridView_DataBinding
| > | 8. GridView_DataBound
| > |
| > | I think that events 5 to 8 are caused by changing the
GridView.PageIndex
| > in
| > | 2.1. The events to not re-fire the second time GridView.PageIndex is
set,
| > | presumably because the PageIndex is already the required value.
| > |
| > | The key thing here is that the database is called twice (and maybe
the
| > page
| > | is rendered on the BRowser twice?) and is thus an overhead that we
should
| > | avoid. Can you help me with a better solution?
| > |
| > |
| > | "Steven Cheng[MSFT]" wrote:
| > |
| > | > Hi Richard,
| > | >
| > | > Welcome to ASPNET newsgroup.
| > | > Regarding on the GridView control's row selection, it is a very
simple
| > | > implementation which dosn't quite associated with the underlying
| > | > datasource, the SelectedIndex only range in the current displayed
page
| > of
| > | > data. So when our page size is set to 5, the available
selectedIndex is
| > | > from 0 to 4....
| > | >
| > | > So when there is changes made on the underlying datasource or page
| > index
| > | > changed... If we still want to keep the original selected dataitem,
I'm
| > | > afraid we have to manually calculate the index of that record on
the
| > | > certain page (according to total records count, page size), then
set
| > the
| > | > proper page index and selected index....
| > | >
| > | > Regards,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | >
| > | >
| > | > --------------------
| > | > | Thread-Topic: Persisting the currently selected row on a GridView
| > | > | thread-index: AcYdOIdSa2b3anygQnilL8UCN+aWPQ==
| > | > | X-WBNR-Posting-Host: 193.130.25.218
| > | > | From: "=?Utf-8?B?RGljaw==?=" <Ri***********@nospam.nospam>
| > | > | Subject: Persisting the currently selected row on a GridView
| > | > | Date: Thu, 19 Jan 2006 12:40:05 -0800
| > | > | Lines: 19
| > | > | Message-ID: <61**********************************@microsoft.co m>
| > | > | MIME-Version: 1.0
| > | > | Content-Type: text/plain;
| > | > | charset="Utf-8"
| > | > | Content-Transfer-Encoding: 7bit
| > | > | X-Newsreader: Microsoft CDO for Windows 2000
| > | > | Content-Class: urn:content-classes:message
| > | > | Importance: normal
| > | > | Priority: normal
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | > | Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet:372201
| > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > | > |
| > | > | I have a GridView bound to an ObjectDataSource. I have a Button
that
| > | > calls
| > | > | GridView.DataBind. I want the row that is selected before the
| > DataBind to
| > | > | still be selected afterwards.
| > | > |
| > | > | This happens automatically if the data doesn't change. But if
records
| > | > have
| > | > | been added or deleted then it looks as if some code is necessary:
| > I've
| > | > done
| > | > | this by using GridView.SelectedValue to get the key value of the
| > | > currently
| > | > | selected Row and then by itterating through the DataKeys
collection
| > | > (after
| > | > | the DataBind has completed) I can work out the RowIndex of the
Row
| > that
| > | > has
| > | > | the same key value. There's some more code to adjust for the
| > GridView's
| > | > | PageIndex but otherwise this works.
| > | > |
| > | > | But what I've not been able to do is adjust for the occassions
when
| > the
| > | > row
| > | > | that I'm hoping to select is no longer on the same PageIndex.
I've
| > got
| > | > close
| > | > | by handling the ObjectDataSource_Selected event and I can now
predict
| > | > which
| > | > | page the row will be on (although I've not tested wither sort
orders
| > | > effect
| > | > | this). But how do I then make the GridView display the correct
page?
| > | > |
| > | > | Hope you can help.
| > | > |
| > | >
| > | >
| > |
| >
| >
|

Jan 23 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: James Baker | last post by:
I have a form that has a dropdown list that will cause a post to the same page when it's changed. The problem I'm running into is that all of the controls reset to their default values (obviously...
2
by: Citoyen du Monde | last post by:
Trying to get some ideas on a simple javascript project (to teach myself the language). I want to develop a client-side vocabulary practice application that would allow users to enter their own...
1
by: lim | last post by:
What is the possible error that occurs when the Page_load event is not triggered during execution. In my page there's some basic server control. Is there any loops holes?
3
by: Carlos | last post by:
Hi all, I currently have a Gridview that doess sorting correctly using several fields. However, I do have a checkbox field that when it is checked I do not know how to make its value to persist...
1
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. ...
2
by: David Ching | last post by:
I am not getting any response to my previous question on reusing a DetailsView to insert and edit the selected row in a GridView. So I'll ask an even more basic question. Newbie alert! ;) When...
1
by: Nikron | last post by:
Hi, I'm having an issue with the ASP.NET 2.0 Treeview control and persisting its' state accross requests. My Control is embedded within a master page and is used for site navigation. My problem...
1
by: neobonzi | last post by:
Hello! I'm dynamically creating a GridView bound to a datatable using custom template columns using the following method: protected void ShowGrid(DataTable dt) { ...
7
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi all, this is a second post, so apologies, but I never had an answer to my first post (several weeks ago) and I really need some help. I'm using a .Net 2.0 Gridview which is populated using an...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.