473,545 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

asp.net datalist display single row

Hi everyone.
Beging a newbee to asp.net and used to work with traditional asp I have
one problem working with a datalist.
1/ I make a dataset as as session variable like
session("employ ees")
2/ I want the datalist do display only the first row of the table.
But it always fails.
tried for exemple:
dim nrowpos as ingeger 'shows the current rowposition
dim dv as dataview
dim dt as datatable (connented to the dataset)
dv = dt.Rows(nRowPos ).ToString()
datalist1.datal ist1.datasource = dv
But everything I tried fails.

Of cource I could instead use av simple web-form without datalist,
but I think that this also must work with a datalist.

I want to do this because I don't want to requery the databas every
time wanted to move to the next record, like you had to to in asp 2.0
Hope someone could help me.

Nov 13 '05 #1
3 4934
First, I should tell you that you're in the wrong newsgroup for this.
I suggest you try one of the ASP.NET newsgroups.

I typically solve the problem by creating a dataset and storing it as a
session variable as in

Dim objDS as New Dataset
objDS = 'Place your code here to create your dataset

'Store the dataset as a session variable
Session("DS") = objDS
From here you could create a DataView to sort the records in the dataset

Dim objDV As DataView = Session("DS").T ables(0).Defaul tView
objDV.Sort = "Column 1 asc"

or you can pick through specific records in your results with a more
precise dataview that includes a criterion

'Filter the records
Dim strValue as String
Dim strID As String = "25"
Dim objDV As DataView = New DataView(Sessio n("DS").Tables( 0),
"ContactID= " & strID, "ContactID" , DataViewRowStat e.CurrentRows)

'Find a matching record (in this case only one record)
Dim i As Integer
i = objDV.Find(strI D)

If i <> -1 Then
strValue =objDV.Item(i)( "Column2")
End If

I can't understand why you're using a Datalist if you want to display
only one record. A datalist is for multiple records and typically
creates an html table. You probably would be better off binding to
individual controls.

Bill Ehrreich

ol**@ylm.se wrote: Hi everyone.
Beging a newbee to asp.net and used to work with traditional asp I have one problem working with a datalist.
1/ I make a dataset as as session variable like
session("employ ees")
2/ I want the datalist do display only the first row of the table.
But it always fails.
tried for exemple:
dim nrowpos as ingeger 'shows the current rowposition
dim dv as dataview
dim dt as datatable (connented to the dataset)
dv = dt.Rows(nRowPos ).ToString()
datalist1.datal ist1.datasource = dv
But everything I tried fails.

Of cource I could instead use av simple web-form without datalist,
but I think that this also must work with a datalist.

I want to do this because I don't want to requery the databas every
time wanted to move to the next record, like you had to to in asp 2.0
Hope someone could help me.


Nov 13 '05 #2
Hi.
Thanks for your help.
Now it works perfekt for me to display only one record
at a time from a database-query.
The reason that I want to do this is that a want users
to be able to:
1/ make a query to get a dataset.table with for example all custumers
from Alabama
2/ Display the first row.
3/ Make changes if wanted.
4/ move to the next row.
and so on.

The good thing with this approach is that att can Cache the Recordset
and move next without having requering the database.(like I had to do
in traditional asp)
and I have all the layout-possibilities of the datalist.

this is how i Did it:
Private Sub UpdateView()
dim lngIdValue as long
Dim nRowPos As Integer = CType(Session(" CurrentRecord") , Integer)
' moving to next record is done by: Session("Curren tRecord") += 1

Dim ds As DataSet = CType(Session(" Northwind"), DataSet)
Dim dt As DataTable = ds.Tables("empl oyees")
dim strFieldname as string = "Emplyeeid"
lngIdValue= dt.Rows(nRowPos )(strFieldname) .ToString()
Dim objDV As DataView = New DataView(ds.Tab les(0),"employe eid=" &
lngIdValue, "employeeid ", DataViewRowStat e.CurrentRows)
datalist1.datas ource = objdv
' Display the data
datalist1.DataB ind()
End Sub

Nov 13 '05 #3
That's great! I'm glad to have been of assistance to you.

Bill

Nov 13 '05 #4

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

Similar topics

1
2255
by: Yoshitha | last post by:
hi I have datalist control in my ASP.NET application the problem here is i have used a textbox with multiline true propertly when i enter data like "fdjsfhjksdhfjsdfhsdjhfsdfhsdjfhsd jfdsjfksdjfksdjkfjsdfjksdjfsdjfd fdsfhjsdhfjsdhfjf dsjf dsjfhjsdfhjksdh d fdsjf hsdjkfhdjsfhsdjfh ds
0
1993
by: Mark | last post by:
Hi, I have a datalist that contains a textbox as well as a dropdown list. For each single row in the datalist the associated dropdown list can have at least one value What I would like to be able to do is when a single update button is clicked the textbox value along with the associated dropdown value is printed for each row in the...
2
2296
by: Allen Davis | last post by:
I have some hierarchical data bound to a series of nested DataLists and DataGrids for which I'd like to be able to provide the end-user some targeted printing capabilities. By that I mean being able to send just one parent dataitem and all its children to the printer. Does anyone have any good suggestions for how to do this or where to look...
2
527
by: Mark | last post by:
I have a datalist (see code below). Assume that the datalist is populated with 10 records of data. How do I programatically grab all the data in ALL the columns of the selected record? I've been trying to use the FindControl method inside the ItemCommand event of the DataList to get the contents of the Label below, but it appears that the...
4
2473
by: Joe Van Meer | last post by:
Hi, Is the datalist meant for one table or can I use it to display information from 2 different tables? Or should I be looking at a datagrid instead? I began my code and kinda ran into a snag where my last two columns I am displaying are ID fields, one for clientid and the other for empid. What I would really like is to display their...
0
1168
by: Shun Duke | last post by:
I have working code allowing me to nest repeaters inside datalists using relations and child rows but this does not allow me to acheive my goal. What I want to be able to do is display small tables (approx 5-10 rows by 3-4 columns) of data using repeaters nested in a datalist. Each row in the datalist source will act as a pointer and...
0
1554
by: Rick Wez | last post by:
I feel like I'm going to pull out my hair (there's not much left); I've read almost every online post trying to figure this out. So I started over with something VERY simple and it still doesn't work ... here we go. I have a datalist with an embedded user control. My user control outputs a single string. The first time thru, everything...
6
2209
by: Victor | last post by:
Hi. all I have a customize web control. I have three simple properties and customized render class. then I add this control into my datalist like <asp:DataList ID="datalist" runat="server" RepeatColumns="3"> <ItemTemplate> <uc:mycontrol id="test" runat="server" /> </ItemTemplate> </asp:DataList> In the code-behind I have something like...
0
1043
by: graphicsxp | last post by:
Hi, I have the following datalist which basically displays dropdownList in 3 columns. <asp:DataList ID="dlFilters" runat="server" RepeatDirection="Vertical" RepeatLayout="Flow" RepeatColumns="3"
0
7668
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. ...
0
7923
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...
0
7773
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
5984
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
5343
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
4960
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
3466
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
3448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1025
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.