views:

202

answers:

1

I've never used either of these 2 controls before and I'm stuck with no visible rendering of the page (compiles and runs but produces nothing); I have no code behind file with this simple asp.net page and I am using Visual Studio 2008:

<%@ Page Language="C#" AutoEventWireup="true" 
    CodeBehind="Index.aspx.cs" Inherits="zList.Index" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" >
   <head runat="server">
        <title></title>
   </head>
<body>
<form id="form1" runat="server">
<div>
    <asp:ListView ID="CategoryList" runat="server" 
            DataSourceID="Categories">
    <LayoutTemplate>
        <ol>
            <asp:PlaceHolder runat="server" ID="itemPlaceholder">
            </asp:PlaceHolder>
        </ol>
    </LayoutTemplate>
       <ItemTemplate>
            <li><%# Eval("AttrDesc")%></li>
       </ItemTemplate>
    </asp:ListView>
</div>
</form>
</body>
</html>
<asp:sqldatasource runat="server" id="Categories"
    ConnectionString="<%$ ConnectionStrings:ZIPeeeConnectionString2 %>" 
    SelectCommand="SELECT AttrID,AttrDesc FROM dbo.tblAttributes1">
</asp:sqldatasource>

Here is the connection string section from web.config (I have tried both connection strings separately and they both result in nothing rendered):

<connectionStrings>
    <add name="ZIPeeeConnectionString" connectionString="Data Source=MOJITO;Initial Catalog=ZIPeee;Integrated Security=True" providerName="System.Data.SqlClient"/>
    <add name="ZIPeeeConnectionString2" connectionString="Data Source=MOJITO;Initial Catalog=ZIPeee;User ID=sa;Password=" providerName="System.Data.SqlClient"/>
</connectionStrings>

I am getting no runtime errors and no errors during the build. The simple query works fine from SQL Query Analyzer (i.e. SQL Server 2000). Any ideas?

EDIT-UPDATE: Here is what I have in my .ASPX.CS code behind file and I cannot get the debugger to stop on the breakpoint on the .DataBind method:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace zList
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CategoryList.DataBind();   // breakpoint set here but debugger won't stop here
        }
    }
}

By the way, I fired up SQL Profiler and it appears the SQL select is not even being fired against the server. As I said, the page is empty - just this junk when I scrape it via View Page Source:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1   /DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title></title></head>
<body>
<form name="form1" method="post" action="Index.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjAyMTkwMzQ3OQ9kFgQCAw9kFgICAQ8UKwACDxYEHgtfIURhdGFCb3VuZGceC18hSXRlbUNvdW50Av////8PZGRkAgUPD2QPEBYDZgIBAgIWAxYCHg5QYXJhbWV0ZXJWYWx1ZWQWAh8CZBYCHwJkFgMCAwIDAgNkZBgBBQxDYXRlZ29yeUxpc3QPZ2TCuhjvuwDRjaGJssTwiDXpAv/fdw==" />
</div>

<div>

</div>
</form>
</body>
</html>
+1  A: 

I think the only thing wrong with this code is the placement of the sqldatasource. Can you place it inside the tag.

If that doesnt work, can you change your listview definition to

<asp:ListView ID="CategoryList" runat="server"> 

and then change your page load code to

CategoryList.DataSource = Categories;
CategoryList.DataBind();

You should be able to hit the debugger

As a last option, can you also check whether the connectionstrings is placed within the Configuration tag in web.config.

rajeshr
Thank you. I discovered that the SqlDataSource had to be inside the <div> too. That is, the SQL D.S. control had to be followed by </div> and then </form>. I am quite rusty on ASP.NET web forms so this is embarrassing. One last question if I may: By experimenting with this simple thing, I believe I discovered that the .DataBind in the Page_Load event is optional (it indeed binds and produces the output with no code inside Page_Load). Is that your understanding also? Please confirm on this. Thanks.
John Galt
In this case, you have already tightly bound your control the data source. The databind option is really useful if you bind data dynamically. Say, all you have is a list view. If the user selects one option, you want to bind it to data from one table. Else, you want to bind it to data from another table. In this case, it is really useful to bind data programatically at run time. This is just a sample scenario. Hope this helps.
rajeshr