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

K

Ken Fine

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
 
E

Eliyahu Goldin

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

Ken Fine

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 said:
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 said:
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
 
E

Eliyahu Goldin

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 said:
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 said:
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 said:
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
 
G

Guest

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 said:
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 said:
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 said:
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


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
 
E

Eliyahu Goldin

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


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 said:
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 said:
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

message 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


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
 
G

Guest

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

-KF


Eliyahu Goldin said:
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


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 said:
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


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

message 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


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
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top