PC Review


Reply
Thread Tools Rate Thread

datalist repeating first record

 
 
Lewis
Guest
Posts: n/a
 
      22nd Aug 2003
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



 
Reply With Quote
 
 
 
 
Ignacio Machin
Guest
Posts: n/a
 
      22nd Aug 2003
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:3f45e17d$0$11382$(E-Mail Removed)...
> 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
>
>
>



 
Reply With Quote
 
Lewis
Guest
Posts: n/a
 
      22nd Aug 2003
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">
<aspataList 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>
</aspataList>
</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.oDSImages1)).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_location", "thumb_location"),
new
System.Data.Common.DataColumnMapping("location_local", "location_local"),
new
System.Data.Common.DataColumnMapping("thumb_location_local",
"thumb_location_local"),
new
System.Data.Common.DataColumnMapping("filename", "filename"),
new
System.Data.Common.DataColumnMapping("thumb_filename", "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.oDSImages1)).EndInit();

}
#endregion
}
}






 
Reply With Quote
 
Ignacio Machin
Guest
Posts: n/a
 
      22nd Aug 2003
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:3f4617aa$0$11383$(E-Mail Removed)...
> 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">
> <aspataList 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>
> </aspataList>
> </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.oDSImages1)).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_location", "thumb_location"),
> new
> System.Data.Common.DataColumnMapping("location_local", "location_local"),
> new
> System.Data.Common.DataColumnMapping("thumb_location_local",
> "thumb_location_local"),
> new
> System.Data.Common.DataColumnMapping("filename", "filename"),
> new
> System.Data.Common.DataColumnMapping("thumb_filename", "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.oDSImages1)).EndInit();
>
> }
> #endregion
> }
> }
>
>
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Datalist HeaderTemplate repeating duplicates? - sort, break, grouping? jobs at webdos Microsoft ASP .NET 2 8th Oct 2006 02:22 PM
Datalist not repeating...why?` Lynn Microsoft ASP .NET 1 16th Aug 2004 10:36 PM
Select a record in datalist and opend form based on that record Eric Blitzer Microsoft Access Forms 1 30th Oct 2003 10:58 PM
datalist repeating first record Lewis Microsoft ASP .NET 4 22nd Aug 2003 02:43 PM
datalist repeating first record Lewis Microsoft C# .NET 3 22nd Aug 2003 02:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:52 AM.