Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 26th, 2004, 07:49 AM
Authorized User
Join Date: Nov 2003
Location: Mataro, Barcelona, Spain.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default Show table in DataList


I want to show a table in a datalist control. I've tried but I can't see nothing in the page when I executed. What's the problem?

            DataRow[] foundRows;

            ds = new DataSet("ALMACEN");
            dt = ds.Tables.Add("PRODUCTOS");
            dt.Columns.Add("id_producto", typeof (Int32));
            dt.Columns.Add("nombre", typeof (String));
            dt.PrimaryKey = new DataColumn[] { dt.Columns["id_productos"] };
            da = new SqlDataAdapter ("SELECT * FROM materia_prima", myConnection);
            da.Fill(ds, "PRODUCTOS");
            foundRows = dt.Select();
            for (int i = 0; i < foundRows.Length; i++)
                dr = dt.NewRow();

                dr[0] = foundRows[i]["id_producto"];
                dr[1] = foundRows[i]["nombre"];


            DataView dv = new DataView(dt);
            dlProductos.DataSource = dv;
            dlProductos.DataKeyField = "id_producto";

World only exists into your mind.
  #2 (permalink)  
Old February 26th, 2004, 10:29 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

It looks to me like you have greatly over complicated this code. I don't think you need to write all that code that creates a table for the dataset. When you use the data adapter to fill the dataset, it will create the table for you. That would at least simplify things. Start with that and see where you get.

ds = new DataSet("ALMACEN");
da = new SqlDataAdapter ("SELECT id_producto, nombre FROM materia_prima", myConnection);
da.Fill(ds, "PRODUCTOS");
dlProductos.DataSource = ds.Tables[0];
dlProductos.DataKeyField = "id_producto";

Work smarter, not harder.

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to show text in datalist while value in NULL nittin14 ASP.NET 1.0 and 1.1 Basics 4 September 1st, 2007 06:28 PM
use datalist via xml to show picture in output zuz29 ASP.NET 2.0 Basics 0 May 27th, 2006 06:51 PM
How to show thumbnail in the GridView/DataList walgr2k ASP.NET 2.0 Basics 1 May 20th, 2006 10:17 AM
Show item in datalist control keyvanjan ASP.NET 1.0 and 1.1 Professional 0 January 14th, 2006 03:44 PM
Bind records from the table to a datalist control macupryk General .NET 1 October 13th, 2004 11:59 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.