<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Displaying a Table of Database Data</title><link>http://www.asp.net</link><pubDate>Sat, 09 Jan 2010 13:37:27 GMT</pubDate><generator>umbraco</generator><description>Comments for Displaying a Table of Database Data</description><language>en</language><atom:link href="http://www.asp.net/rss/comments/27485" rel="self" type="application/rss+xml" /><item><title>Comment Posted by cv_vikram</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Wed, 27 Aug 2008 07:01:23 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006881</guid><description><![CDATA[ <p>thanks....</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/cv_vikram.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by sn33zingpanda</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Mon, 15 Sep 2008 22:47:30 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006882</guid><description><![CDATA[ <p>Trying to follow along with your vb code in C#. &#160;When I run the app for the first time, I get</p> <p>Line 13: &lt;% foreach (Call c in ViewData.Model)%&gt;</p> <p>CS1579: foreach statement cannot operate on variables of type &#39;object&#39; because &#39;object&#39; does not contain a public definition for &#39;GetEnumerator&#39;</p> <p>I&#39;ve tried to remove my dbml and re-create it following your pattern. &#160;I have a Calls table that I have dropped onto my Call model.</p> <p>Not sure if there&#39;s a difference between C# and VB that&#39;s biting me here, or if I&#39;m simply missing a step.</p> <p>Good video overall... high quality video and audio, good presentation.</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/sn33zingpanda.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by swalther</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Tue, 16 Sep 2008 14:29:04 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006883</guid><description><![CDATA[ <p>@sn33zingpanda -- Yes, this is a difference between C# and VB.NET. In C#, you must explicitly cast ViewData.Model to an IEnumerable in your foreach loop:</p> <p>&lt;% foreach (var c in (IEnumerable)ViewData.Model) { %&gt;</p> <p>The other option is to use a strongly typed view. When you create a strongly-typed view, you specify the type of the ViewData.Model property in your code-behind class.</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/swalther.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by amanprogrammer</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Tue, 16 Sep 2008 17:24:14 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006884</guid><description><![CDATA[ <p>Stephen You rock.</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/amanprogrammer.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by sboys</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Wed, 22 Oct 2008 07:00:33 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006885</guid><description><![CDATA[ <p>I am trying to add a Mvc View user control as shown in the video but the code in the Index.aspx page is failing on the RenderUserControl line.</p> <p>&lt;% foreach (Project p in (IEnumerable)ViewData.Model)</p> <p> &#160; { %&gt; </p> <p> &#160; &#160; &#160; &#160;&lt;%= Html.RenderUserControl (ViewData.Model, &quot;~/Views/Home/ProjectTemplate.ascx&quot;, p); %&gt;</p> <p>&lt;% } %&gt;</p> <p>The error message is &#39;System.Web.Mvc.HtmlHelper&#39; does not contain a definition for &#39;RenderUserControl&#39; and no extension method &#39;RenderUserControl&#39; acceptin a first argument of type &#39;System.Web.Mvc.HtmlHelper&#39; could be found.</p> <p>I have the following in the Index.aspx.cs:</p> <p>using System;</p> <p>using System.Collections.Generic;</p> <p>using System.Linq;</p> <p>using System.Web;</p> <p>using System.Web.Mvc;</p> <p>using MvcCorporate.Models;</p> <p>namespace MvcCorporate.Views.Home</p> <p>{</p> <p> &#160; &#160;public partial class Index : ViewPage</p> <p> &#160; &#160;{</p> <p> &#160; &#160;}</p> <p>}</p> <p>How do I get access to the RenderUserControl?</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/sboys.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by fchalip</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Wed, 22 Oct 2008 20:13:54 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006886</guid><description><![CDATA[ <p>How about displaying 2 tables in the View. </p> <p>Let say we want to display 2 different LinkToSql Queries (Top 5 New Releases and Movies directed by &#160;Steven Spielberg)</p> <p>How we do that if return View on the Controller only accepts one Model object?</p> <p>Francisco</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/fchalip.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by mstum</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Wed, 22 Oct 2008 20:17:47 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006887</guid><description><![CDATA[ <p>Thank you! I&#39;m even going to overlook that &quot;Star Wars II&quot; mistake you did in the movie table :P Good work on the videos, they rock!</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/mstum.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by anthonywjones66</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Sun, 16 Nov 2008 15:53:25 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006888</guid><description><![CDATA[ <p>Preview 5 is now using Html.RenderPartial instead of RenderUserControl</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/anthonywjones66.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by worldlifesite</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Sun, 21 Dec 2008 13:31:58 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006889</guid><description><![CDATA[ <p>Another very great series. &#160;This really helps those new to MVC, makes it quick to pick up.</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/worldlifesite.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by DaseinMind</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Tue, 23 Dec 2008 15:27:59 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006890</guid><description><![CDATA[ <p>Microsoft definitely ought to provide video series of this quality together for every major technology. &#160;However, is anyone else hearing creepy bubbles and noises in the background (11:24)?</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/DaseinMind.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by DotNetNoobiee</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Wed, 07 Jan 2009 13:32:21 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006891</guid><description><![CDATA[ <p>Hi everyone, hope i can get some help on this, and I have a gut feeling that this will be considered as an extremely stupid question, but i&#39;m also a REAL noob when it comes to .Net.</p> <p>I&#39;ve looked at a lot of the tutorial videos, which are amazing btw, and i can follow along quite nicely.</p> <p>I tried a simple Mvc application using Linq2SQL and C#.</p> <p>I&#39;m getting an &quot;InvalidCastException was unhandled by user code&quot; error when i try to display my client table the same as in the video (except i&#39;m doing it in C#).</p> <p>this is my code.</p> <p>AdminController:</p> <p> &#160; &#160; &#160; &#160;public ActionResult ClientList()</p> <p> &#160; &#160; &#160; &#160;{</p> <p> &#160; &#160; &#160; &#160; &#160; &#160;myDataContext dataContext = new myDataContext();</p> <p> &#160; &#160; &#160; &#160; &#160; &#160;var client = from c in dataContext.Clients &#160; select c;</p> <p> &#160;return View(client);</p> <p>}</p> <p>clientList.aspx:</p> <p>&lt;%@ Page Title=&quot;&quot; Language=&quot;C#&quot; MasterPageFile=&quot;~/Views/Shared/Site.Master&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;ClientList.aspx.cs&quot; Inherits=&quot;cbia.Views.Admin.ClientList&quot; %&gt;</p> <p>&lt;%@ Import Namespace=&quot;MvcApplication1.Models&quot; %&gt;</p> <p>&lt;asp:Content ID=&quot;Content1&quot; ContentPlaceHolderID=&quot;MainContent&quot; runat=&quot;server&quot;&gt;</p> <p> &#160; &#160;&lt;table border=&quot;1&quot;&gt;</p> <p> &#160; &#160;&lt;tr&gt;</p> <p> &#160; &#160; &#160; &#160;&lt;td&gt;test data&lt;/td&gt;</p> <p> &#160; &#160;&lt;/tr&gt;</p> <p> &#160; &#160; &#160; &#160;&lt;% &#160; &#160; &#160; &#160; &#160; &#160;</p> <p> &#160; &#160; &#160; &#160; &#160; &#160;foreach (Client c in (IEnumerable)ViewData.Model)</p> <p> &#160; &#160; &#160; &#160; &#160; &#160;{</p> <p> &#160; &#160; &#160; &#160;%&gt;</p> <p> &#160; &#160; &#160; &#160;&lt;tr&gt;</p> <p> &#160; &#160; &#160; &#160; &#160; &#160;&lt;td&gt;</p> <p> &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;%= c.name%&gt;</p> <p> &#160; &#160; &#160; &#160; &#160; &#160;&lt;/td&gt;</p> <p> &#160; &#160; &#160; &#160; &#160; &#160;&lt;td&gt;</p> <p> &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;%= c.address%&gt;</p> <p> &#160; &#160; &#160; &#160; &#160; &#160;&lt;/td&gt;</p> <p> &#160; &#160; &#160; &#160; &#160; &#160;&lt;td&gt;</p> <p> &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;%= c.isActive%&gt;</p> <p> &#160; &#160; &#160; &#160; &#160; &#160;&lt;/td&gt;</p> <p> &#160; &#160; &#160; &#160;&lt;/tr&gt;</p> <p> &#160; &#160; &#160; &#160;&lt;% } %&gt;</p> <p> &#160; &#160;&lt;/table&gt;</p> <p>&lt;/asp:Content&gt;</p> <p>I would appreciate any guidance in this matter!</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/DotNetNoobiee.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by DotNetNoobiee</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Mon, 02 Feb 2009 15:41:16 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006892</guid><description><![CDATA[ <p>Hi peeps,</p> <p>I managed to fix the problem by erasing all the tables from my .dbml file and re-import the tables, i suppose the project was corrupt or something, hence why i was getting the exception.</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/DotNetNoobiee.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by .netDeveloper22</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Wed, 04 Feb 2009 10:04:10 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006893</guid><description><![CDATA[ <p>Thanks Stephen</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/.netDeveloper22.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by marafacs</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Fri, 20 Mar 2009 03:34:22 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006894</guid><description><![CDATA[ <p>Thanks stephen... excellent video</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/marafacs.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by pradipjalu</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Sat, 11 Apr 2009 06:51:23 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006895</guid><description><![CDATA[ <p>Thanks Stephen for providing nice video tutorial on table data format in ASP.Net MVC application.</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/pradipjalu.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by vinothkumarsi</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Sat, 18 Apr 2009 07:26:18 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006896</guid><description><![CDATA[ <p>Thanks Stephen</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/vinothkumarsi.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by kwilson1997</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Tue, 05 May 2009 16:10:58 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006897</guid><description><![CDATA[ <p>I had a rough time following along using C#.NET 2008.  I finally got it to work.</p><p></p><p>~/Views/Home/Index.aspx :</p><p>=========================</p><p>&lt;%@ Import Namespace=&quot;MvcSample.Models&quot;%&gt;</p><p>...</p><p>&lt;% </p><p>   foreach (Movie m in (IEnumerable) ViewData.Model) {</p><p>      Html.RenderPartial(&quot;~/Views/Home/MovieTemplate.ascx&quot;, m);</p><p>   } </p><p>%&gt;</p><p></p><p>NOTE: &quot;RenderUserControl()&quot; does not exist.  I&#39;m guessing it was replaced with &quot;Html.RenderPartial()&quot; which is what I used above.</p><p></p><p></p><p>~/Views/Home/MovieTemplate.ascx:</p><p>================================</p><p>&lt;%@ Import Namespace=&quot;MvcSample.Models&quot;%&gt;</p><p>&lt;tr&gt;</p><p>   &lt;td&gt;&lt;%= (ViewData.Model as Movie).Id %&gt;&lt;/td&gt;</p><p>   &lt;td&gt;&lt;%= Server.HtmlEncode((ViewData.Model as Movie).Title)%&gt;&lt;/td&gt;</p><p>   &lt;td&gt;&lt;%= (ViewData.Model as Movie).DateReleased.ToShortDateString()%&gt;&lt;/td&gt;</p><p>&lt;/tr&gt;</p><p></p><p>NOTE: There is no code behind file for this control.  None was ever created.  I can&#39;t see any way to strongly type the current record except to use &quot;(ViewData.Model as Movie)&quot; as I did in my code above.  Is there a better way to do this?</p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/kwilson1997.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by stallings_st@hotmail.com</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Mon, 18 May 2009 20:21:15 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006898</guid><description><![CDATA[ <p>I have a hard time tried to figure out.... why no code behind file when i created mvc user control. Thank you kwilson1997.</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/stallings_st@hotmail.com.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by Talley123</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Wed, 20 May 2009 05:12:20 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006899</guid><description><![CDATA[ <p>Great video for MVC novice like me.Thanks</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/Talley123.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by weitzhandler</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Thu, 18 Jun 2009 01:40:49 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006900</guid><description><![CDATA[ <p>thanks!</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/weitzhandler.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by currentspulledmeunder</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Fri, 03 Jul 2009 13:20:43 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006901</guid><description><![CDATA[ <p>I wish this was in C#, I&#39;m having trouble following.  My dataContext doesn&#39;t have a GetTable command, just the fields of my table.  I&#39;m not sure what I did wrong.</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/currentspulledmeunder.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by francke peixoto</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Mon, 24 Aug 2009 10:42:43 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006902</guid><description><![CDATA[ <p>very good!  ;-)</p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/francke%20peixoto.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by zeyzone</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Fri, 09 Oct 2009 17:18:46 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006903</guid><description><![CDATA[ <p>Good work</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/zeyzone.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by shadyrudy</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Thu, 15 Oct 2009 21:58:21 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006904</guid><description><![CDATA[ <p>Wish there was a C# version. :/</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/shadyrudy.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by abulmohsin</title><link>http://www.asp.net/mvc/videos/mvc-2/how-do-i/displaying-a-table-of-database-data</link><pubDate>Sat, 09 Jan 2010 13:37:27 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006905</guid><description><![CDATA[ <p>please post C# version..</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/abulmohsin.jpg?forceidenticon=false&amp;dt=635046112200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item></channel></rss>