473,785 Members | 2,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What to consider when using SqlDatASource programmaticall y?

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("S ELECT id, fname, lname FROM user")

gridview1.datas ource = myDS.Datasource ' <- sqldatasource
gridview1.datab ind

On gridview1.Selec tedIndexChange

myDetailDs = new myDatasource("S ELECT * FROM WHERE Id = @id")
myDetailDs.Sele ctParameters.ad d("Id", gridview1.selec tedDatakey)
detailview1.dat asource = myDetailDs.data source
detailview1.dat abind
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 2539
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 ObjectDataSourc e."

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
2034
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 the applicable fields in the gridview to a sqldatasource which in turn calls a sproc with the appropriate parameters and data. Any ideas? Thanks in advance,
3
11284
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: <asp:SqlDataSource ID="DataSource1" runat="server" ConnectionString="<%$ ConnectionStrings: ConnectionString1 %>" SelectCommand="UserLkp" SelectCommandType="StoredProcedure"
3
12734
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 on how to handle different tasks programmatically such as selects, updates, sorting of data etc. in code behind if I prefer to set all Gridview and Sqldatasource properties etc. in code behind rather than in the aspx file.
3
2904
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 I expected to be able to use it like the below Dim ds as dataset SqlDataSource1. fill ( ds) ' does not work
2
3443
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 datagrida. I would like to set it so that if value of column 3 in datagrid 1 is < 100 set to red, if = 100 set to green if value of column 3 in datagrid 2 is < 90 set to red, if >= 90 set to green if value of column 3 in datagrid 3is < 80 set to red,...
3
1483
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 in the aspx file. The creation of the templatefields are done programmatically, because the number of fields vary (fieldnames are fetched from the same sqldatasource). Now, my problem: no error, the detailsview renders the right fieldheaders...
2
1348
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 loop through it. and get the extra columns passed in the sqldatasource01 I don't want to loop through the CheckBoxList because it does not have all the extra columns.
1
1168
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" AutoGenerateColumns="False" OnSelectedIndexChanged="Search_GridView_SelectedIndexChanged" CellPadding="20" Width="720px" AllowPaging="True" OnPageIndexChanging="Search_GridView_PageIndexChanging" DataSourceID="SqlDataSource1"> ...
0
798
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 via a session object. So on the second page, can the selection criteria be specified in a SqlDataSource object? or should I do it programmatically in the page load event? Thanks for any insight.
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10153
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.