0

我以前从未使用过这两个控件中的任何一个,并且无法看到页面的可见渲染(编译并运行但什么也没产生);我没有这个简单的 asp.net 页面的代码隐藏文件,我正在使用 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">
<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>

这是 web.config 中的连接字符串部分(我已经分别尝试了两个连接字符串,它们都没有渲染):

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

我在构建过程中没有遇到运行时错误和错误。简单查询在 SQL 查询分析器(即 SQL Server 2000)中运行良好。有任何想法吗?

编辑更新:这是我在文件后面的 .ASPX.CS 代码中的内容,我无法让调试器在 .DataBind 方法的断点处停止:

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

顺便说一句,我启动了 SQL Profiler,似乎 SQL 选择甚至没有针对服务器启动。正如我所说,该页面是空的 - 当我通过查看页面源抓取它时只是这个垃圾:

<!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>
4

1 回答 1

2

我认为这段代码唯一的问题是 sqldatasource 的位置。你能把它放在标签里面吗?

如果这不起作用,您可以将您的列表视图定义更改为

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

然后将您的页面加载代码更改为

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

您应该能够点击调试器

作为最后一个选项,您是否还可以检查连接字符串是否放置在 web.config 的配置标记中。

于 2010-02-16T16:32:50.300 回答