473,581 Members | 6,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I'm lazy: how do I make the first databound record not display/chop off the first element from SqlDataSource

I'm using ASP.NET 2.0, C#, SQL Server 2005, and databound controls like the
DataList and the GridView. Right now I'm using SqlDataSource as part of very
quick and dirty site; I'm not looking to tier things.

I want the topmost/first data element in a particular control to NOT be
displayed. This should be possible by either telling the renderer to hide
the first element programmaticall y, or by deleting it from the data store
that it has grabbed. I suppose I could also write a stored procedure to only
return the data I wanted, or accomplish this through programming, but I am
curious about what solutions are possible that a) are as easy as possible,
and b) still permit me to databound controls declaratively.

Any suggestions on how I could do this?

Thank you,
Ken Fine

Jun 22 '06 #1
7 1746
Ken,

Handle PreRender event. In the event the items collection is already fully
build and you can easily navigate to the first item and hide it with either
Visible property or css rule display:none.

Eliyahu

<ke*****@nospam .nospam> wrote in message
news:uw******** ******@TK2MSFTN GP04.phx.gbl...
I'm using ASP.NET 2.0, C#, SQL Server 2005, and databound controls like
the DataList and the GridView. Right now I'm using SqlDataSource as part
of very quick and dirty site; I'm not looking to tier things.

I want the topmost/first data element in a particular control to NOT be
displayed. This should be possible by either telling the renderer to hide
the first element programmaticall y, or by deleting it from the data store
that it has grabbed. I suppose I could also write a stored procedure to
only return the data I wanted, or accomplish this through programming, but
I am curious about what solutions are possible that a) are as easy as
possible, and b) still permit me to databound controls declaratively.

Any suggestions on how I could do this?

Thank you,
Ken Fine

Jun 22 '06 #2
Thank you. I have been unable to make this work in spite of a fair bit of
reading and hacking around. This seems the most germane:
http://www.codecomments.com/archive3...10-657712.html

My efforts at being lazy are quickly being thwarted ;). I would be just as
happy knowing how to intercept the DataSet that is returned by SqlDataSource
and programmaticall y whacking off the topmost row. Any suggestions? One
thing that isn't clear to me is what that DataSet ends up being named, and
when it becomes accessible in the page lifecycle, when you do things
directly/lazily using SqlDataSource.

-KF

"Eliyahu Goldin" <re************ *@monarchmed.co m> wrote in message
news:e7******** *****@TK2MSFTNG P05.phx.gbl...
Ken,

Handle PreRender event. In the event the items collection is already fully
build and you can easily navigate to the first item and hide it with
either Visible property or css rule display:none.

Eliyahu

<ke*****@nospam .nospam> wrote in message
news:uw******** ******@TK2MSFTN GP04.phx.gbl...
I'm using ASP.NET 2.0, C#, SQL Server 2005, and databound controls like
the DataList and the GridView. Right now I'm using SqlDataSource as part
of very quick and dirty site; I'm not looking to tier things.

I want the topmost/first data element in a particular control to NOT be
displayed. This should be possible by either telling the renderer to hide
the first element programmaticall y, or by deleting it from the data store
that it has grabbed. I suppose I could also write a stored procedure to
only return the data I wanted, or accomplish this through programming,
but I am curious about what solutions are possible that a) are as easy as
possible, and b) still permit me to databound controls declaratively.

Any suggestions on how I could do this?

Thank you,
Ken Fine


Jun 22 '06 #3
Hi,

Thank you for your post.

SqlDataSource has a DataSourceMode property which by default set to DataSet
mode, another mode is DataReader mode which uses IDataReader object. Based
on my research, there's no way to get the internal DataSet object of
SqlDataSource when the DataSourceMode set to DataSet.

I think currently the workaround using CSS rules to hide the rows is the
most acceptable one.

Please feel free to post here if anything is unclear.

Regards,
Walter Wang
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 23 '06 #4
So I found two solutions, one OK, one good, and both in keeping with the
"quick and dirty" premise of my original question.

The OK solution is using CSS to hide an element, but it comes with a cavet
on a two-column datalist.
The good solution for my purposes is to write an inline SQL subquery to
define the datasource.

Details follow.

SOLUTION #1: DATALIST ITEM SET TO "HIDDEN"
For the CSS/Hidden hack, do as follows in the .ascx .cs code:

protected void DataList2_ItemC reated(object sender, DataListItemEve ntArgs e)
{
if (e.Item.ItemInd ex == 0)
{
e.Item.CssClass = "Hidden";

}
}

on the .ascx I deployed this to:

<asp:DataList ID="DataList2" runat="server" DataSourceID="S qlDataSource2"
RepeatColumns=" 2" CellPadding="6" Width="87%" RepeatDirection ="Horizontal "
OnItemCreated=" DataList2_ItemC reated">

.... and on the master page, in the <head> section:

<style>
.Hidden {display:none;}
</style>

SOLUTION #2: WRITE A SUBQUERY
I didn't want to write a sproc, but I don't mind a good query. A subquery
will do the trick

SELECT ContentID, Title, Subtitle
FROM Contentitems
WHERE (ContentID NOT IN
(SELECT TOP (1) ContentID
FROM Contentitems AS
Contentitems_1
WHERE (CategoryID = 34))) AND
(CategoryID = 34)
ORDER BY PubDate DESC

Thanks to everyone for their help.

-KF

<ke*****@nospam .nospam> wrote in message
news:eQ******** ******@TK2MSFTN GP05.phx.gbl...
Thank you. I have been unable to make this work in spite of a fair bit of
reading and hacking around. This seems the most germane:
http://www.codecomments.com/archive3...10-657712.html

My efforts at being lazy are quickly being thwarted ;). I would be just as
happy knowing how to intercept the DataSet that is returned by
SqlDataSource and programmaticall y whacking off the topmost row. Any
suggestions? One thing that isn't clear to me is what that DataSet ends up
being named, and when it becomes accessible in the page lifecycle, when
you do things directly/lazily using SqlDataSource.

-KF

"Eliyahu Goldin" <re************ *@monarchmed.co m> wrote in message
news:e7******** *****@TK2MSFTNG P05.phx.gbl...
Ken,

Handle PreRender event. In the event the items collection is already
fully build and you can easily navigate to the first item and hide it
with either Visible property or css rule display:none.

Eliyahu

<ke*****@nospam .nospam> wrote in message
news:uw******** ******@TK2MSFTN GP04.phx.gbl...
I'm using ASP.NET 2.0, C#, SQL Server 2005, and databound controls like
the DataList and the GridView. Right now I'm using SqlDataSource as part
of very quick and dirty site; I'm not looking to tier things.

I want the topmost/first data element in a particular control to NOT be
displayed. This should be possible by either telling the renderer to
hide the first element programmaticall y, or by deleting it from the data
store that it has grabbed. I suppose I could also write a stored
procedure to only return the data I wanted, or accomplish this through
programming, but I am curious about what solutions are possible that a)
are as easy as possible, and b) still permit me to databound controls
declaratively.

Any suggestions on how I could do this?

Thank you,
Ken Fine



Jun 23 '06 #5

Thanks much, Walter. That's an interesting limit of SqlDataSource. Is there
a design premise for why this internal dataset would not be exposed? Maybe
MSFT wants to avoid breaking something known by n00bs to be bindable in the
IDE? Or is it some other consideration?

All of the ADO.NET books go on and on about the DataSet's in-memory
capabilities; it's a little funny that you can't get at it when
SqlDataSource grabs one.

-KF

"Walter Wang [MSFT]" <wa****@online. microsoft.com> wrote in message
news:4I******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi,

Thank you for your post.

SqlDataSource has a DataSourceMode property which by default set to
DataSet
mode, another mode is DataReader mode which uses IDataReader object. Based
on my research, there's no way to get the internal DataSet object of
SqlDataSource when the DataSourceMode set to DataSet.

I think currently the workaround using CSS rules to hide the rows is the
most acceptable one.

Please feel free to post here if anything is unclear.

Regards,
Walter Wang
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jun 23 '06 #6
Hi,

Thank you for your summary on this. This will benefit the community a lot.

ObjectDataSourc e is another DataSource object in ASP.NET 2.0 which has many
great features. You can find more information about ObjectDataSourc e here:

#DataSource Controls and Declarative Programming
http://www.nikhilk.net/DataSourceControlThoughts.aspx

#Data Points: Data Source Controls in ASP.NET 2.0
http://msdn.microsoft.com/msdnmag/is...01/DataPoints/

In your case about removing the top rows with the easiest way, I think
ObjectDataSourc e can help you do this with a strong typed DataSet. Here's
some brief steps:

1) In Visual Studio 2005, add a new DataSet object, follow the wizard to
configure it, you can choose to use SQL statements or Stored Procedures;
2) On the WebForm, add an ObjectDataSourc e and configure it to use the
generated DataSet's TableAdapter;
3) Bind a GridView to this ObjectDataSourc e;
4) Handle ObjectDataSourc e's Selected Event:

protected void ObjectDataSourc e1_Selected(obj ect sender,
ObjectDataSourc eStatusEventArg s e)
{
DataSet2.Employ eesDataTable dt = e.ReturnValue as
DataSet2.Employ eesDataTable;
for (int i = 0; i < 8; i++)
{
dt.Rows.RemoveA t(0);
}
}

This will remove top 8 rows from the result DataTable.

Hope this helps. Please feel free to post here if anything is unclear.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 24 '06 #7
Hi,

It is by intentional design that there is no Page-level access to the data
returned from a data source control, since the interface for selecting data
is intended only for data-bound controls. If you need to have access to the
DataSet before it is returned to the data-bound control, consider using
ObjectDataSourc e so your SelectMethod can retrieve the DataSet in code.

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 28 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1976
by: spmm_pls | last post by:
Hi, Could some1 please tell me what the best way is to adjust the value of a column in my databound datagrid (in ASP.NET) For example my database returns the values 1,2 and 3 in the column Priority. But 1,2 and 3 actually represent "Low", "Medium" and "High". So instead of a column filled with 1,2,3's I want a column filled with...
4
3274
by: blackhawk | last post by:
I need to build a web page that has to potentially display a large amount of data in two grids on the same page. The HTML file with all of the formatting is about 7MB in size. This is too large and I need to implement some kind of "client side" lazy loading. What I mean is this: I want to display a grid that only shows, say, 20 records....
0
1098
by: anyeone | last post by:
I'm finding articles all over the place saying how to bind a dropdownlist to an objectdatasource or sqldatasource in .NET 2.0/VS2005 but nothing that says how to get the selected value from another datasource. Here's the scenario. I'm essentially loading an order for a client. There is a dropdownlist (ddlClient) with a list of clients...
5
14102
by: clickon | last post by:
This is driving me nuts, it is such a simply thing to do but i cannot for the life of me work out how you are suposed to do it. I want to update the data in DropDownListB based on what is selected in DropDownListA. I am not trying to do anything fancy with AJAX, i am happy to use Post Backs. If it were two controls just on the page then i...
0
1211
by: fig000 | last post by:
Hi, I'm trying to use the sqldatasource control and a detailsview to create a fully functional data entry screen; it's quite easy. I can see the strength of creating a master grid associated with a detailsview that gives you access to the record you choose in the grid. However one of the basic functions of this type of screen is the...
2
1716
by: cider123 | last post by:
I have a SqlDataSource bound to a DropDownList Combo. Works just fine. I noticed 2 properties you can set in the DropDownList, 1 for the value to be displayed in the "Text" column and 1 for the value to be used in the "Value" property. I'm at a catch 22 right now though.. The SqlDataSource gets 2 field values.. "Name" and "Description".
1
7112
by: anjali.lourda | last post by:
Hi, We are trying to use the accordion control from ajaxcontroltoolkit by databinding to an sqldatasource. The accordion binds to the datasource perfectly. However, We are not able to access the controls or their values which were bound. Please let me know which is the away to access that Given below is the code. Please let me know if any...
1
3191
by: David C | last post by:
I have a FormView that I want to do something to avoid a data exception. The control is bound to a SqlDataSource column and is giving me an exception because it is null. I am using the DropDownCalendar control from Steve Orr and I have the SelectedDate property bound to a datetime column. Is there something I can do before data binding to...
1
3085
by: Pipo Dyer | last post by:
Hello Everybody, I am Using @@IDENTITY from MS Access (YES-It is possible) using SqlDataSource -NO STORE PROC- in ASP.NET {VB CODE} to retrieve the ID of a inserted record. Please keep in mind I am using a form page an code behing, and I have currently my ConnectionString within my form. Therefore...
0
7783
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...
0
8134
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. ...
1
7880
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...
0
8157
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...
0
6539
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...
1
5665
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...
0
5350
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...
0
3794
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...
0
3807
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.