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

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

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
6 2016
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? Example: I have an SqlDataSource with a...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
8
by: Radx | last post by:
Here in my web application, I have a data entry page with serval controls. Some of the controls have autopostback is set true. But the problem is when two or more people are entering data at the...
1
by: Mike P | last post by:
When you use a SqlDataSource to hook up data to a GridView it seems to be to be very inflexible. For example, I want to create my own Delete button with my own code and I also want to create a...
7
by: | last post by:
I'm using ASP.NET 2.0, C#, SQL Server 2005, and databound controls like the DataList and the GridView. Right now I'm using SqlDataSource as part of very quick and dirty site; I'm not looking to...
4
by: Mike | last post by:
Is there any difference in performance between a SqlDataSource and an ObjectDataSource - assuming they are being deployed to perform the same task against a SQL Server database? Mike
1
by: Chris | last post by:
Hi, I want to limit the amount of data shown in a page coming from a database. Everything works except that I get the error: "Unable to cast object of type...
4
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This...
0
by: =?Utf-8?B?UEs5?= | last post by:
I have a very simple setup that should work fine per documentation. However, my gridview control will not properly update using the updatecommand of the sqldatasource. I've simplified everything...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.