What to consider when using SqlDatASource programmatically?

V

Vili

Hi all

I would like to get some ideas and opinions of my solution for
dataconnection on asp.net 2.0

I have created a class which encapsulates the sqldatasource usage.

With my class one can set select-, insert-, update- and deletecommand
with and without parameters and also get output parameters


Typical usage from code-behind:

I might have one gridview and a detailview on my page.

I fill my gridview like this

I set up my datasources on the top of the code so that they can be
used from all over on that page class

On page load:

myDS = new myDatasource("SELECT id, fname, lname FROM user")

gridview1.datasource = myDS.Datasource ' <- sqldatasource
gridview1.databind

On gridview1.SelectedIndexChange

myDetailDs = new myDatasource("SELECT * FROM WHERE Id = @id")
myDetailDs.SelectParameters.add("Id", gridview1.selectedDatakey)
detailview1.datasource = myDetailDs.datasource
detailview1.databind


All of this works fine but I am still not sure if this is the best way
to go. At the moment all my sql statements are in code-behind and I am
not sure how I could remove all that from to own layer. Maybe create a
separate function for all the statements? Does not sound the perfect
solution.

How does paging on datagrid happen in this case? Can sqldatasource
handle it well or does all the data still stay in viewstate? If so,
how to fix this?


Regards,
Vili
 
V

Vili

How does paging on datagrid happen in this case? Can sqldatasource
handle it well or does all the data still stay in viewstate? If so,
how to fix this?

It seems that I found an answer for the paging part.

Quote from GridView Examples for ASP.NET 2.0: Paging and Sorting the
GridView's Data - http://msdn2.microsoft.com/en-us/library/aa479347.aspx
"The downside of using a SqlDataSource as a pageable GridView's data
source control is that the GridView uses the default paging model.
That is, on each page request the SqlDataSource returns all of the
records that are to be paged through to the GridView. The GridView
then picks out the correct subset of records based on the number of
records to show per page and the page index. In order to implement the
custom paging model you'll need to use an ObjectDataSource."

Any ideas how to get the paging work better with sqldatasource?

Regards,
Vili
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top