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

What to consider when using SqlDatASource programmatically?

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

Similar topics

1
by: P | last post by:
Hello, I am having a difficult time updating a record via a stored procedure using the gridview and sqldatasource. I cannot seem to be able to find a way to set everything up so that I can pass...
3
by: michelle | last post by:
I am trying to get an output value from a stored procedure using sqlDataSource in asp.net 2.0. But I only get a null value for the output. Can someone please help? The sqlDataSource: ...
3
by: Dorte | last post by:
Hi, Could someone help me with a couple of links to SqlDatasource documentation on how to use the Gridview and SqlDatasource components in code behind? Basically I'm missing some documentation...
3
by: Bill | last post by:
This is probably easy but I cannot find it... All I want to do is read the data out of a SQLDataSource programmatically to test if there are any records. I don't want to bind it to a control ...
2
by: Mike Baugh | last post by:
I am using visual studio 2005 to develop a form using c# I have 3 datagrids on one form. I can set the row color based on a certain value in a column. However this color applies to all 3...
3
by: Cas | last post by:
Hi, I want to use a detailsview only for inserting data into a database (for a survey). In order to check the inputted data, i need Templatefield. So I defined a detailsview and a SqlDataSource...
2
by: LVP | last post by:
Hi, I have a sqldatasource01 configured properly and can databind it to a CheckBoxList and see data with no problem. How can I get the data programmatically from the sqldatasource01 I need to...
1
by: sweatha | last post by:
Hi I connected SQLDataSource in GridView by using coding <asp:GridView ID="Search_GridView" runat="server" Style="z-index: 100; left: 2px; position: absolute; top: 270px"...
0
by: E. Kwong | last post by:
On a page after the user presses the Submit button, he/she will be sent to a second page where his/her records are displayed in Gridview. The record selection is based on a user ID which is passed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.