473,770 Members | 4,055 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 2538
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
3442
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
9425
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
10230
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9870
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
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...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
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...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
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
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.