By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,316 Members | 2,317 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,316 IT Pros & Developers. It's quick & easy.

asp.net datalist display single row

P: n/a
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("employees")
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.datalist1.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
Share this Question
Share on Google+
3 Replies


P: n/a
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").Tables(0).DefaultView
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(Session("DS").Tables(0),
"ContactID=" & strID, "ContactID", DataViewRowState.CurrentRows)

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

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("employees")
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.datalist1.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

P: n/a
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("CurrentRecord") += 1

Dim ds As DataSet = CType(Session("Northwind"), DataSet)
Dim dt As DataTable = ds.Tables("employees")
dim strFieldname as string = "Emplyeeid"
lngIdValue= dt.Rows(nRowPos)(strFieldname).ToString()
Dim objDV As DataView = New DataView(ds.Tables(0),"employeeid=" &
lngIdValue, "employeeid", DataViewRowState.CurrentRows)
datalist1.datasource = objdv
' Display the data
datalist1.DataBind()
End Sub

Nov 13 '05 #3

P: n/a
That's great! I'm glad to have been of assistance to you.

Bill

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.