473,382 Members | 1,329 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.

datalist repeating first record

Hey!

Wondering if anyone can help!

I have been trying to build an aspx page which builds a list of records from
a database. Having been doing this using xml and xslt using asp for years
with no problems this particular page had some functionality which I thought
could be well suited to a data list control.
Maybe I'm misunderstanding how this control is supposed to work but it
doesn't do what I'm expecting!

Here's what I did: (briefly)

* added the connection, adapter and dataset (creating the xsd as well) to my
aspx page.
* previewed the dataset (all OK)
* added the data list to the page.
* edited the 'tem' template - and added a literal control.
* set the datalists's datasource to be my dataset
* bound the literal control to a column in my dataset
* added the code to fill the dataset and bind everything on the page to its
databindings

The page compiled OK and when viewed it had 16 literal controls (the same
amount of records as is in my table) : but all controls had the value from
the first row of my table.
After trying to figure this out I decided to check that the number of
records wasn't just a coincidence so I removed all but two records - the
page then showed just two literal controls!
I have successfully got this working with a datagrid but a datalist suits my
needs more appropriately. Am I misunderstanding how the datalist control is
supposed to work?

Wish Id used XML / XSLT to start off with now. : (

Thanks in advance for the help!

Lewis

Nov 15 '05 #1
5 3384
Hi Lewis,

Can you please post some code.

Thanks,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Lewis" <Lewis_at_arc_dot_com> wrote in message
news:3f***********************@news.dial.pipex.com ...
Hey!

Wondering if anyone can help!

I have been trying to build an aspx page which builds a list of records from a database. Having been doing this using xml and xslt using asp for years
with no problems this particular page had some functionality which I thought could be well suited to a data list control.
Maybe I'm misunderstanding how this control is supposed to work but it
doesn't do what I'm expecting!

Here's what I did: (briefly)

* added the connection, adapter and dataset (creating the xsd as well) to my aspx page.
* previewed the dataset (all OK)
* added the data list to the page.
* edited the 'tem' template - and added a literal control.
* set the datalists's datasource to be my dataset
* bound the literal control to a column in my dataset
* added the code to fill the dataset and bind everything on the page to its databindings

The page compiled OK and when viewed it had 16 literal controls (the same
amount of records as is in my table) : but all controls had the value from
the first row of my table.
After trying to figure this out I decided to check that the number of
records wasn't just a coincidence so I removed all but two records - the
page then showed just two literal controls!
I have successfully got this working with a datagrid but a datalist suits my needs more appropriately. Am I misunderstanding how the datalist control is supposed to work?

Wish Id used XML / XSLT to start off with now. : (

Thanks in advance for the help!

Lewis

Nov 15 '05 #2
Hi Lewis,

Can you please post some code.

Thanks,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Lewis" <Lewis_at_arc_dot_com> wrote in message
news:3f***********************@news.dial.pipex.com ...
Hey!

Wondering if anyone can help!

I have been trying to build an aspx page which builds a list of records from a database. Having been doing this using xml and xslt using asp for years
with no problems this particular page had some functionality which I thought could be well suited to a data list control.
Maybe I'm misunderstanding how this control is supposed to work but it
doesn't do what I'm expecting!

Here's what I did: (briefly)

* added the connection, adapter and dataset (creating the xsd as well) to my aspx page.
* previewed the dataset (all OK)
* added the data list to the page.
* edited the 'tem' template - and added a literal control.
* set the datalists's datasource to be my dataset
* bound the literal control to a column in my dataset
* added the code to fill the dataset and bind everything on the page to its databindings

The page compiled OK and when viewed it had 16 literal controls (the same
amount of records as is in my table) : but all controls had the value from
the first row of my table.
After trying to figure this out I decided to check that the number of
records wasn't just a coincidence so I removed all but two records - the
page then showed just two literal controls!
I have successfully got this working with a datagrid but a datalist suits my needs more appropriately. Am I misunderstanding how the datalist control is supposed to work?

Wish Id used XML / XSLT to start off with now. : (

Thanks in advance for the help!

Lewis

Nov 15 '05 #3
code follows

(pretty much all generated by VS.net )
ASPX: -->

<%@ Page language="c#" Codebehind="imagesDL.aspx.cs" AutoEventWireup="false"
Inherits="namespace.subnamespace.imagesDL" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>imagesDL</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="imagesDL" method="post" runat="server">
<asp:DataList id=DataList1 style="Z-INDEX: 101; LEFT: 2px; POSITION:
absolute; TOP: 12px" runat="server" DataSource="<%# oDSImages1 %>"
DataMember="IMAGE" DataKeyField="image_id">
<ItemTemplate>
<asp:Literal id=Literal1 runat="server" Text='<%#
DataBinder.Eval(oDSImages1, "Tables[IMAGE].DefaultView.[0].caption") %>'>
</asp:Literal>
</ItemTemplate>
</asp:DataList>
</form>
</body>
</HTML>

code behind : --->
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace namespace.subnamespace
{
/// <summary>
/// Summary description for imagesDL.
/// </summary>
public class imagesDL : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected WelshHeroes._admin.oDSImages oDSImages1;
protected System.Web.UI.WebControls.DataList DataList1;

private void Page_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(oDSImages1);
Page.DataBind();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.oDSImages1 = new WelshHeroes._admin.oDSImages();

((System.ComponentModel.ISupportInitialize)(this.o DSImages1)).BeginInit();
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table",
"IMAGE", new System.Data.Common.DataColumnMapping[] {
new
System.Data.Common.DataColumnMapping("image_id", "image_id"),
new
System.Data.Common.DataColumnMapping("name", "name"),
new
System.Data.Common.DataColumnMapping("caption", "caption"),
new
System.Data.Common.DataColumnMapping("location", "location"),
new
System.Data.Common.DataColumnMapping("thumb_locati on", "thumb_location"),
new
System.Data.Common.DataColumnMapping("location_loc al", "location_local"),
new
System.Data.Common.DataColumnMapping("thumb_locati on_local",
"thumb_location_local"),
new
System.Data.Common.DataColumnMapping("filename", "filename"),
new
System.Data.Common.DataColumnMapping("thumb_filena me", "thumb_filename"),
new
System.Data.Common.DataColumnMapping("isLive", "isLive")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT image_id, name, caption,
location, thumb_location, location_local, thumb_l" +
"ocation_local, filename, thumb_filename, isLive FROM IMAGE";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "connstring";
//
// oDSImages1
//
this.oDSImages1.DataSetName = "oDSImages";
this.oDSImages1.Locale = new System.Globalization.CultureInfo("en-GB");
this.oDSImages1.Namespace = "http://www.tempuri.org/oDSImages.xsd";
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.o DSImages1)).EndInit();

}
#endregion
}
}


Nov 15 '05 #4
code follows

(pretty much all generated by VS.net )
ASPX: -->

<%@ Page language="c#" Codebehind="imagesDL.aspx.cs" AutoEventWireup="false"
Inherits="namespace.subnamespace.imagesDL" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>imagesDL</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="imagesDL" method="post" runat="server">
<asp:DataList id=DataList1 style="Z-INDEX: 101; LEFT: 2px; POSITION:
absolute; TOP: 12px" runat="server" DataSource="<%# oDSImages1 %>"
DataMember="IMAGE" DataKeyField="image_id">
<ItemTemplate>
<asp:Literal id=Literal1 runat="server" Text='<%#
DataBinder.Eval(oDSImages1, "Tables[IMAGE].DefaultView.[0].caption") %>'>
</asp:Literal>
</ItemTemplate>
</asp:DataList>
</form>
</body>
</HTML>

code behind : --->
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace namespace.subnamespace
{
/// <summary>
/// Summary description for imagesDL.
/// </summary>
public class imagesDL : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected WelshHeroes._admin.oDSImages oDSImages1;
protected System.Web.UI.WebControls.DataList DataList1;

private void Page_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(oDSImages1);
Page.DataBind();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.oDSImages1 = new WelshHeroes._admin.oDSImages();

((System.ComponentModel.ISupportInitialize)(this.o DSImages1)).BeginInit();
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table",
"IMAGE", new System.Data.Common.DataColumnMapping[] {
new
System.Data.Common.DataColumnMapping("image_id", "image_id"),
new
System.Data.Common.DataColumnMapping("name", "name"),
new
System.Data.Common.DataColumnMapping("caption", "caption"),
new
System.Data.Common.DataColumnMapping("location", "location"),
new
System.Data.Common.DataColumnMapping("thumb_locati on", "thumb_location"),
new
System.Data.Common.DataColumnMapping("location_loc al", "location_local"),
new
System.Data.Common.DataColumnMapping("thumb_locati on_local",
"thumb_location_local"),
new
System.Data.Common.DataColumnMapping("filename", "filename"),
new
System.Data.Common.DataColumnMapping("thumb_filena me", "thumb_filename"),
new
System.Data.Common.DataColumnMapping("isLive", "isLive")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT image_id, name, caption,
location, thumb_location, location_local, thumb_l" +
"ocation_local, filename, thumb_filename, isLive FROM IMAGE";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "connstring";
//
// oDSImages1
//
this.oDSImages1.DataSetName = "oDSImages";
this.oDSImages1.Locale = new System.Globalization.CultureInfo("en-GB");
this.oDSImages1.Namespace = "http://www.tempuri.org/oDSImages.xsd";
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.o DSImages1)).EndInit();

}
#endregion
}
}


Nov 15 '05 #5
Hi Lewis,

Try changing this bind expression from :

<ItemTemplate>
<asp:Literal id=Literal1 runat="server"
Text='<%#DataBinder.Eval(oDSImages1,
"Tables[IMAGE].DefaultView.[0].caption") %>'>
</asp:Literal>
</ItemTemplate>

to:

<ItemTemplate>
<span><%#DataBinder.Eval( Container.DataItem, "caption") %></span>
</asp:Literal>
</ItemTemplate>
I change the literal control to <Span> cause the latter does not generate
overload on the server side.
beside that I think that the problem is in the first parameter of Eval ( )
it should be Container.DataItem

Try it and let me know,

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Lewis" <Lewis_at_arc_dot_com> wrote in message
news:3f***********************@news.dial.pipex.com ...
code follows

(pretty much all generated by VS.net )
ASPX: -->

<%@ Page language="c#" Codebehind="imagesDL.aspx.cs" AutoEventWireup="false" Inherits="namespace.subnamespace.imagesDL" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>imagesDL</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="imagesDL" method="post" runat="server">
<asp:DataList id=DataList1 style="Z-INDEX: 101; LEFT: 2px; POSITION:
absolute; TOP: 12px" runat="server" DataSource="<%# oDSImages1 %>"
DataMember="IMAGE" DataKeyField="image_id">
<ItemTemplate>
<asp:Literal id=Literal1 runat="server" Text='<%#
DataBinder.Eval(oDSImages1, "Tables[IMAGE].DefaultView.[0].caption") %>'>
</asp:Literal>
</ItemTemplate>
</asp:DataList>
</form>
</body>
</HTML>

code behind : --->
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace namespace.subnamespace
{
/// <summary>
/// Summary description for imagesDL.
/// </summary>
public class imagesDL : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected WelshHeroes._admin.oDSImages oDSImages1;
protected System.Web.UI.WebControls.DataList DataList1;

private void Page_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(oDSImages1);
Page.DataBind();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.oDSImages1 = new WelshHeroes._admin.oDSImages();

((System.ComponentModel.ISupportInitialize)(this.o DSImages1)).BeginInit();
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "IMAGE", new System.Data.Common.DataColumnMapping[] {
new
System.Data.Common.DataColumnMapping("image_id", "image_id"),
new
System.Data.Common.DataColumnMapping("name", "name"),
new
System.Data.Common.DataColumnMapping("caption", "caption"),
new
System.Data.Common.DataColumnMapping("location", "location"),
new
System.Data.Common.DataColumnMapping("thumb_locati on", "thumb_location"),
new
System.Data.Common.DataColumnMapping("location_loc al", "location_local"),
new
System.Data.Common.DataColumnMapping("thumb_locati on_local",
"thumb_location_local"),
new
System.Data.Common.DataColumnMapping("filename", "filename"),
new
System.Data.Common.DataColumnMapping("thumb_filena me", "thumb_filename"),
new
System.Data.Common.DataColumnMapping("isLive", "isLive")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT image_id, name, caption,
location, thumb_location, location_local, thumb_l" +
"ocation_local, filename, thumb_filename, isLive FROM IMAGE";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "connstring";
//
// oDSImages1
//
this.oDSImages1.DataSetName = "oDSImages";
this.oDSImages1.Locale = new System.Globalization.CultureInfo("en-GB");
this.oDSImages1.Namespace = "http://www.tempuri.org/oDSImages.xsd";
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.o DSImages1)).EndInit();
}
#endregion
}
}


Nov 15 '05 #6

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

Similar topics

6
by: Umut K. | last post by:
Hi all, I've a DataList control and it's DataBound by a SqlDataReader... The Reader returns say 3 records and as expected the datalist shows 3 rows. What i want to do is to add another extra...
3
by: olle | last post by:
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/...
4
by: Lewis | last post by:
Hey! Wondering if anyone can help! I have been trying to build an aspx page which builds a list of records from a database. Having been doing this using xml and xslt using asp for years with...
1
by: Lynn | last post by:
Hello, Sorry for the double post...I meant for this to go into this forum. I have built a datalist programatically using an article from MSDN...the article was written specifically for the...
6
by: Paul | last post by:
I am trying to use a DataList and the ItemTemplate. I am binding the Datalist to a SQL query that gives me a list of Items with a Parent Category. I want to loop through all the items, but...
1
by: Jim in Arizona | last post by:
I'm don't know how I would get around this. When working with a datalist control, there a specific built in commands (OnEditCommand, OnCancelCommand, etc). These commands, when the datalist...
2
by: jobs at webdos | last post by:
I have data that looks like this prodid fileid date where prodid repeats I want report like this prodid - fileid date
1
by: studen771 | last post by:
Thanks in advance to anyone who can help :) I have my datalist bound to a normal, single dimension string array (with three elements) as its data source. In the scripting for the datagrid, I have...
1
by: Brock | last post by:
First note that I am using Framework 1.1. I have an .aspx page that is displaying a list of employees, but only the Employee Number, First Name, Last Name, and Title. It is working great. I...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.