473,382 Members | 1,435 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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("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
3 4904
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
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
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
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...
0
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...
2
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...
2
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...
4
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...
0
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...
0
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...
6
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"...
0
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"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.