By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,536 Members | 2,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,536 IT Pros & Developers. It's quick & easy.

SQLDataSource and asp.net data display: iterating only the middle of the collection?

P: n/a
I'm using SQLDataSource, which generates some kind of dataset, and then I
attach that datasource to various data display controls such as DataList and
repeater which loop through to the end of the data that was retrieved by the
query.

At times I may want the display control only to render some items in the set
of data returned by SqlDataSource. There would be several scenarios:

* render the second data item or third item in to the end
* render the second data item through the second-to-the-last or
third-to-the-last data item
* render the first data item through N and then stop rendering.

I recognize that it would be possible to accomplish the same thing by
manipulating what gets pulled out of the database, but I'd like to have
alternatives to that. Using ASP/ADO I could have managed this by playing
with the cursor and MoveNext and the like.

Ultimately I want to be able to specify parameters to user controls at
runtime and tell an embedded repeater to, say, render items 2-5 in a list of
data items. This will serve various layout and content management needs.

Can someone suggest code to accomplish the three bulleted scenarios
described above?

-KF

Dec 26 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
A simple way of doing this would be to bind the whole dataset to the
repeater and than handle the repeater's PreRender event to set Visible=false
for some items according to your rules.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Ken Fine" <ke*****@u.washington.eduwrote in message
news:em**********@gnus01.u.washington.edu...
I'm using SQLDataSource, which generates some kind of dataset, and then I
attach that datasource to various data display controls such as DataList
and repeater which loop through to the end of the data that was retrieved
by the query.

At times I may want the display control only to render some items in the
set of data returned by SqlDataSource. There would be several scenarios:

* render the second data item or third item in to the end
* render the second data item through the second-to-the-last or
third-to-the-last data item
* render the first data item through N and then stop rendering.

I recognize that it would be possible to accomplish the same thing by
manipulating what gets pulled out of the database, but I'd like to have
alternatives to that. Using ASP/ADO I could have managed this by playing
with the cursor and MoveNext and the like.

Ultimately I want to be able to specify parameters to user controls at
runtime and tell an embedded repeater to, say, render items 2-5 in a list
of data items. This will serve various layout and content management
needs.

Can someone suggest code to accomplish the three bulleted scenarios
described above?

-KF

Dec 26 '06 #2

P: n/a
Thank you. Can anyone suggest if there other approaches that might also
solve the problem? Using the equivalent of a cursor? Copying SqlDataSource
and removing elements from the copy? Applying the equivalent of ".Filter"?

Thanks again for your help,
-KF

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:u7**************@TK2MSFTNGP06.phx.gbl...
>A simple way of doing this would be to bind the whole dataset to the
repeater and than handle the repeater's PreRender event to set
Visible=false for some items according to your rules.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Ken Fine" <ke*****@u.washington.eduwrote in message
news:em**********@gnus01.u.washington.edu...
>I'm using SQLDataSource, which generates some kind of dataset, and then I
attach that datasource to various data display controls such as DataList
and repeater which loop through to the end of the data that was retrieved
by the query.

At times I may want the display control only to render some items in the
set of data returned by SqlDataSource. There would be several scenarios:

* render the second data item or third item in to the end
* render the second data item through the second-to-the-last or
third-to-the-last data item
* render the first data item through N and then stop rendering.

I recognize that it would be possible to accomplish the same thing by
manipulating what gets pulled out of the database, but I'd like to have
alternatives to that. Using ASP/ADO I could have managed this by playing
with the cursor and MoveNext and the like.

Ultimately I want to be able to specify parameters to user controls at
runtime and tell an embedded repeater to, say, render items 2-5 in a list
of data items. This will serve various layout and content management
needs.

Can someone suggest code to accomplish the three bulleted scenarios
described above?

-KF


Dec 26 '06 #3

P: n/a
Sure. You can use DataTable.Select method for filtering records. You will
need a field telling you the item number that you could filter based on the
number.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Ken Fine" <ke*****@u.washington.eduwrote in message
news:em**********@gnus01.u.washington.edu...
Thank you. Can anyone suggest if there other approaches that might also
solve the problem? Using the equivalent of a cursor? Copying SqlDataSource
and removing elements from the copy? Applying the equivalent of ".Filter"?

Thanks again for your help,
-KF

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:u7**************@TK2MSFTNGP06.phx.gbl...
>>A simple way of doing this would be to bind the whole dataset to the
repeater and than handle the repeater's PreRender event to set
Visible=false for some items according to your rules.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Ken Fine" <ke*****@u.washington.eduwrote in message
news:em**********@gnus01.u.washington.edu...
>>I'm using SQLDataSource, which generates some kind of dataset, and then
I attach that datasource to various data display controls such as
DataList and repeater which loop through to the end of the data that was
retrieved by the query.

At times I may want the display control only to render some items in the
set of data returned by SqlDataSource. There would be several scenarios:

* render the second data item or third item in to the end
* render the second data item through the second-to-the-last or
third-to-the-last data item
* render the first data item through N and then stop rendering.

I recognize that it would be possible to accomplish the same thing by
manipulating what gets pulled out of the database, but I'd like to have
alternatives to that. Using ASP/ADO I could have managed this by playing
with the cursor and MoveNext and the like.

Ultimately I want to be able to specify parameters to user controls at
runtime and tell an embedded repeater to, say, render items 2-5 in a
list of data items. This will serve various layout and content
management needs.

Can someone suggest code to accomplish the three bulleted scenarios
described above?

-KF



Dec 26 '06 #4

P: n/a
Does SqlDataSource expose a DataTable that is programmatically accessible
using DataTable.Select? (Apologies in advance for twenty questions, but I am
vaguely vaguely recalling something about SqlDtaSource internally using a
structure that could not be programmatically manipulated in the way you'd
think you could based on its name.)

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:eh**************@TK2MSFTNGP03.phx.gbl...
Sure. You can use DataTable.Select method for filtering records. You will
need a field telling you the item number that you could filter based on
the number.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Ken Fine" <ke*****@u.washington.eduwrote in message
news:em**********@gnus01.u.washington.edu...
>Thank you. Can anyone suggest if there other approaches that might also
solve the problem? Using the equivalent of a cursor? Copying
SqlDataSource and removing elements from the copy? Applying the
equivalent of ".Filter"?

Thanks again for your help,
-KF

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:u7**************@TK2MSFTNGP06.phx.gbl...
>>>A simple way of doing this would be to bind the whole dataset to the
repeater and than handle the repeater's PreRender event to set
Visible=false for some items according to your rules.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Ken Fine" <ke*****@u.washington.eduwrote in message
news:em**********@gnus01.u.washington.edu...
I'm using SQLDataSource, which generates some kind of dataset, and then
I attach that datasource to various data display controls such as
DataList and repeater which loop through to the end of the data that
was retrieved by the query.

At times I may want the display control only to render some items in
the set of data returned by SqlDataSource. There would be several
scenarios:

* render the second data item or third item in to the end
* render the second data item through the second-to-the-last or
third-to-the-last data item
* render the first data item through N and then stop rendering.

I recognize that it would be possible to accomplish the same thing by
manipulating what gets pulled out of the database, but I'd like to have
alternatives to that. Using ASP/ADO I could have managed this by
playing with the cursor and MoveNext and the like.

Ultimately I want to be able to specify parameters to user controls at
runtime and tell an embedded repeater to, say, render items 2-5 in a
list of data items. This will serve various layout and content
management needs.

Can someone suggest code to accomplish the three bulleted scenarios
described above?

-KF





Dec 26 '06 #5

P: n/a
Hmm... Actually with SqlDataSource it is more complicated. You can set
DataSourceMode property to DataSet and the data will be loaded into a
DataSet object. The object will be cashed. The Select method in this case
returns just a list of data rows. You can set the FilterExpression property
prior to calling Select.

I would definitely recommend using the PreRender event. Or switching from
SqlDataSource to the old good DataSource way of databinding where you can
bind to a dataset in a straightforward manner.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
<ke*****@nospam.nospamwrote in message
news:Oe**************@TK2MSFTNGP06.phx.gbl...
Does SqlDataSource expose a DataTable that is programmatically accessible
using DataTable.Select? (Apologies in advance for twenty questions, but I
am vaguely vaguely recalling something about SqlDtaSource internally using
a structure that could not be programmatically manipulated in the way
you'd think you could based on its name.)

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:eh**************@TK2MSFTNGP03.phx.gbl...
>Sure. You can use DataTable.Select method for filtering records. You will
need a field telling you the item number that you could filter based on
the number.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Ken Fine" <ke*****@u.washington.eduwrote in message
news:em**********@gnus01.u.washington.edu...
>>Thank you. Can anyone suggest if there other approaches that might also
solve the problem? Using the equivalent of a cursor? Copying
SqlDataSource and removing elements from the copy? Applying the
equivalent of ".Filter"?

Thanks again for your help,
-KF

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:u7**************@TK2MSFTNGP06.phx.gbl...
A simple way of doing this would be to bind the whole dataset to the
repeater and than handle the repeater's PreRender event to set
Visible=false for some items according to your rules.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Ken Fine" <ke*****@u.washington.eduwrote in message
news:em**********@gnus01.u.washington.edu...
I'm using SQLDataSource, which generates some kind of dataset, and
then I attach that datasource to various data display controls such as
DataList and repeater which loop through to the end of the data that
was retrieved by the query.
>
At times I may want the display control only to render some items in
the set of data returned by SqlDataSource. There would be several
scenarios:
>
* render the second data item or third item in to the end
* render the second data item through the second-to-the-last or
third-to-the-last data item
* render the first data item through N and then stop rendering.
>
I recognize that it would be possible to accomplish the same thing by
manipulating what gets pulled out of the database, but I'd like to
have alternatives to that. Using ASP/ADO I could have managed this by
playing with the cursor and MoveNext and the like.
>
Ultimately I want to be able to specify parameters to user controls at
runtime and tell an embedded repeater to, say, render items 2-5 in a
list of data items. This will serve various layout and content
management needs.
>
Can someone suggest code to accomplish the three bulleted scenarios
described above?
>
-KF
>
>
>




Dec 26 '06 #6

P: n/a
Thanks for the help and clarification. If anyone has a pointer to code, I
would benefit from seeing it.

-KF
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:uh**************@TK2MSFTNGP04.phx.gbl...
Hmm... Actually with SqlDataSource it is more complicated. You can set
DataSourceMode property to DataSet and the data will be loaded into a
DataSet object. The object will be cashed. The Select method in this case
returns just a list of data rows. You can set the FilterExpression
property prior to calling Select.

I would definitely recommend using the PreRender event. Or switching from
SqlDataSource to the old good DataSource way of databinding where you can
bind to a dataset in a straightforward manner.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
<ke*****@nospam.nospamwrote in message
news:Oe**************@TK2MSFTNGP06.phx.gbl...
>Does SqlDataSource expose a DataTable that is programmatically accessible
using DataTable.Select? (Apologies in advance for twenty questions, but I
am vaguely vaguely recalling something about SqlDtaSource internally
using a structure that could not be programmatically manipulated in the
way you'd think you could based on its name.)

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:eh**************@TK2MSFTNGP03.phx.gbl...
>>Sure. You can use DataTable.Select method for filtering records. You
will need a field telling you the item number that you could filter
based on the number.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Ken Fine" <ke*****@u.washington.eduwrote in message
news:em**********@gnus01.u.washington.edu...
Thank you. Can anyone suggest if there other approaches that might also
solve the problem? Using the equivalent of a cursor? Copying
SqlDataSource and removing elements from the copy? Applying the
equivalent of ".Filter"?

Thanks again for your help,
-KF

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:u7**************@TK2MSFTNGP06.phx.gbl...
>A simple way of doing this would be to bind the whole dataset to the
>repeater and than handle the repeater's PreRender event to set
>Visible=false for some items according to your rules.
>
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
>
>
"Ken Fine" <ke*****@u.washington.eduwrote in message
news:em**********@gnus01.u.washington.edu...
>I'm using SQLDataSource, which generates some kind of dataset, and
>then I attach that datasource to various data display controls such
>as DataList and repeater which loop through to the end of the data
>that was retrieved by the query.
>>
>At times I may want the display control only to render some items in
>the set of data returned by SqlDataSource. There would be several
>scenarios:
>>
>* render the second data item or third item in to the end
>* render the second data item through the second-to-the-last or
>third-to-the-last data item
>* render the first data item through N and then stop rendering.
>>
>I recognize that it would be possible to accomplish the same thing by
>manipulating what gets pulled out of the database, but I'd like to
>have alternatives to that. Using ASP/ADO I could have managed this by
>playing with the cursor and MoveNext and the like.
>>
>Ultimately I want to be able to specify parameters to user controls
>at runtime and tell an embedded repeater to, say, render items 2-5 in
>a list of data items. This will serve various layout and content
>management needs.
>>
>Can someone suggest code to accomplish the three bulleted scenarios
>described above?
>>
>-KF
>>
>>
>>
>
>




Dec 26 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.