<%@ Page language="c#" Codebehind="imagesDL.aspx.cs" AutoEventWireup="false" Inherits="namespace.subnamespace.imagesDL" %> imagesDL
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 description for imagesDL. /// 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); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// 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 } } [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <3f4617aa$0$11383$cc9e4d1f@news.dial.pipex.com> [ref] => <3f45e17d$0$11382$cc9e4d1f@news.dial.pipex.com> [htmlstate] => on_nl2br [postusername] => Lewis [ip] => [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 4 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> > > <%@ Page language="c#" Codebehind="imagesDL.aspx.cs"[/ref] AutoEventWireup="false"[ref] > Inherits="namespace.subnamespace.imagesDL" %> > > > > imagesDL > > > > content="http://schemas.microsoft.com/intellisense/ie5"> > > >
> DataMember="IMAGE" DataKeyField="image_id"> > > > > > >
> > > > 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 description for imagesDL. > /// > 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); > } > > /// > /// Required method for Designer support - do not modify > /// the contents of this method with the code editor. > /// > 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[/ref] System.Data.Common.DataTableMapping("Table",[ref] > "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); >[/ref] ((System.ComponentModel.ISupportInitialize)(this.oDSImages1)).EndInit();[ref] > > } > #endregion > } > } > > > > > >[/ref] [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => <3f45e17d$0$11382$cc9e4d1f@news.dial.pipex.com> <3f4617aa$0$11383$cc9e4d1f@news.dial.pipex.com> [htmlstate] => on_nl2br [postusername] => Ignacio [ip] => [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 5 [islastshown] => 1 [isfirstshown] => [attachments] => [allattachments] => ) --> datalist repeating first record - ASP.NET General

datalist repeating first record - ASP.NET General

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 ...

  1. #1

    Default 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



    Lewis Guest

  2. #2

    Default Re: datalist repeating first record

    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$dial.pipex.com... 
    from 
    thought 
    my 
    its 
    my 
    is 


    Ignacio Guest

  3. #3

    Default Re: datalist repeating first record

    Lewis,

    What layout are you using Horizontal or Vertical ?

    Paste some code from "ItemTemplate" part.....

    Thanks,

    Tap
     [/ref]
    list of records [/ref]
    using asp for years [/ref]
    functionality which I [/ref]
    to work but it [/ref]
    the xsd as well) to [/ref]
    control. [/ref]
    everything on the page to [/ref]
    controls (the same [/ref]
    had the value from [/ref]
    the number of [/ref]
    two records - the [/ref]
    but a datalist suits [/ref]
    datalist control 
    >
    >
    >.
    >[/ref]
    Tapasvi Guest

  4. #4

    Default Re: datalist repeating first record

    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
    }
    }






    Lewis Guest

  5. #5

    Default Re: datalist repeating first record

    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$dial.pipex.com... 
    AutoEventWireup="false" 
    System.Data.Common.DataTableMapping("Table", 
    ((System.ComponentModel.ISupportInitialize)(this.o DSImages1)).EndInit(); 


    Ignacio Guest

Similar Threads

  1. How can i retrieve record ONLY From 300 - 400 in amillion Record Table?
    By keonglah in forum Coldfusion Database Access
    Replies: 6
    Last Post: June 13th, 02:53 AM
  2. Find record w/ conditions met in the same child record
    By Thomas Berg in forum FileMaker
    Replies: 2
    Last Post: October 21st, 05:01 AM
  3. Replies: 1
    Last Post: October 3rd, 04:20 PM
  4. Stop adding record in subform after record count = 1
    By Charlie in forum Microsoft Access
    Replies: 0
    Last Post: July 31st, 10:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •