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

What to consider when using SqlDatASource programmatically?

P: n/a
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

Apr 3 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Apr 3 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.