[调试] FormView不显示数据 [英] [debug] FormView not displaying data
问题描述
我正在运行此代码,在我的笔记本电脑(Win XP SP 3/ASP.NET 3.5 SP1)上,以及< asp:formview xmlns:asp =#unknown">似乎未在我的网页内呈现任何数据.
I''m running this code, on my laptop (Win XP SP 3/ASP.NET 3.5 SP1), and, the <asp:formview xmlns:asp="#unknown"> does not seem to render any data within my webpage.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Articles.aspx.cs" Inherits="Articles" %>
<!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 id="Head1" runat="server">
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<title>@Jon's</title>
</head>
<body>
<form id="form1" runat="server">
<h1>@Jon's <img src="images/sofa.jpg" alt="logo"/> </h1 >
<div style="float:left;width:122px">
<p style="width: 122px; height: 663px; margin-top: 0px; margin-right: 0px;">
<a href="About.aspx">About me</a> <br />
<a href="Diary.aspx">My diary</a> <br />
<a href="Articles.aspx">Articles</a> <br />
<a href="Bookmarks.aspx">My bookmarks</a> <br />
<a href="Promotions.aspx">Promotions</a> <br />
<a href="Resume.aspx">My resume</a> <br />
<a href="Warez.aspx">Filesharing</a> <br />
</p>
</div>
<div>
<asp:Calendar ID="calArticles" runat="server" BackColor="White"
BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="180px"
Width="200px" onselectionchanged="calArticles_SelectionChanged">
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<SelectorStyle BackColor="#CCCCCC" />
<WeekendDayStyle BackColor="#4AA02C" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<OtherMonthDayStyle ForeColor="#808080" />
<NextPrevStyle VerticalAlign="Bottom" />
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
</asp:Calendar>
<asp:FormView ID="Envelope" runat="server" DataSourceID="SqlDataSource1"
AllowPaging="True">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<p> <asp:TextBox runat="server" Width="1000" ReadOnly="true" ID="txtSubject"></asp:TextBox> </p>
<p> <asp:TextBox runat="server" Height="300" Width="1000" ReadOnly="true" ID="txtBody" TextMode="MultiLine"></asp:TextBox>
</ItemTemplate>
</asp:FormView>
<p> <asp:Button ID="btnFirst" runat="server" Text="|<" Enabled="True" />
<asp:Button ID="btnPrev" runat="server" Text="<<" Enabled="True" />
<asp:Button ID="btnNext" runat="server" Text=">>" Enabled="True" />
<asp:Button ID="btnLast" runat="server" Text=">|" Enabled="True" />
</p>
<asp:Button ID="btnNew" runat="server" Text="New" />
<asp:Button ID="btnSave" runat="server" Text="Save" />
<asp:Button ID="btnRefresh" runat="server" Text="Refresh" />
<asp:Button ID="btnDelete" runat="server" Text="Delete" Enabled="False" />
<p>
<asp:TextBox ID="TextBox2" runat="server" Width="211px"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" />
</p>
<p>
<asp:Label ID="lblFooter" runat="server"></asp:Label>
</p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:couch_dbConnectionString %>"
SelectCommand="SELECT [Timestamp], [Subject], [EntryText] FROM [Article]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
我已经检查了在SQL Server 2005 Management Studio的VS 2008中生成的SQL语句,它运行正常.
I have checked the SQL Statement generated within VS 2008 on SQL Server 2005 Management Studio and it works fine.
SELECT [Timestamp], [Subject], [EntryText]
FROM [Article] WHERE [Timestamp] >= '8/27/2010 12:00:00 AM' AND
[Timestamp] < (DATEADD(day, 1, [Timestamp]));
SQL结果
SQL Result
2010-08-28 00:00:00.000 subject test
2010-08-28 00:00:00.000 subject 2 test 2
我以前曾考虑过使用XML文件,但是,有人告诉我在编写文件时无法附加到相同的xml文件,因此我决定对数据使用SQL Server数据库. < formview>有一个类似的问题,因为当在第1页和第2页之间切换时,它没有在有效的XML文件中呈现项目.
:confused:
I had previously considered using XML files, however, I was told that it is not possible to append to the same xml file when writing it, so I decided to use a SQL Server database for my data. The <formview> had a similar problem, in that it was not rendering the items within the valid XML file, when flipping between page 1 and page 2.
:confused:
推荐答案
ConnectionStrings:couch_dbConnectionString %> " SelectCommand =" 从[文章]中选择[时间戳记],[主题],[EntryText]" < > < /div > < /form > < /body > < /html >
ConnectionStrings:couch_dbConnectionString %>" SelectCommand="SELECT [Timestamp], [Subject], [EntryText] FROM [Article]"></asp:SqlDataSource> </div> </form> </body> </html>
我已经检查了在SQL Server 2005 Management Studio的VS 2008中生成的SQL语句,它运行正常.
I have checked the SQL Statement generated within VS 2008 on SQL Server 2005 Management Studio and it works fine.
SELECT [Timestamp], [Subject], [EntryText]
FROM [Article] WHERE [Timestamp] >= '8/27/2010 12:00:00 AM' AND
[Timestamp] < (DATEADD(day, 1, [Timestamp]));
SQL结果
SQL Result
2010-08-28 00:00:00.000 subject test
2010-08-28 00:00:00.000 subject 2 test 2
我以前曾考虑过使用XML文件,但是,有人告诉我在编写该文件时不可能附加到相同的xml文件,因此我决定对数据使用SQL Server数据库. < formview>有一个类似的问题,因为当在第1页和第2页之间切换时,它没有在有效的XML文件中呈现项目.
:confused:
I had previously considered using XML files, however, I was told that it is not possible to append to the same xml file when writing it, so I decided to use a SQL Server database for my data. The <formview> had a similar problem, in that it was not rendering the items within the valid XML file, when flipping between page 1 and page 2.
:confused:
FormView
实际上是一个基于Template
的控件(这意味着,您必须定义要绑定到itemtemplate
元素内的哪个控件的字段. >
我没有运行您的代码,但是正如我所看到的,您没有使用Bind()
数据绑定表达式将TextBox
控件(在FormView
的ItemTemplate
部分中)与任何数据绑定.这是您没有在UI中显示任何数据的主要原因(假设其他代码都可以).
这是操作方法(此文本框与EntryText
字段绑定)
FormView
is actually aTemplate
based control (That means, you have to define which field to bind to which control inside theitemtemplate
element.
I didn''t run your code, but as I can see, you are not binding yourTextBox
controls (Inside theFormView
''sItemTemplate
section) with any data using theBind()
Data binding expression. This is the main reason you are not getting any data shown in the UI (Assuming that the other codes are OK).
Here is how to do it (This text box is being bound with theEntryText
field)
<asp:TextBox runat="server" Width="1000" Text=''<%# Bind("EntryText") %>'' ReadOnly="true" ID="txtSubject"></asp:TextBox>
您可以在这里查看一些FormView
示例: http://quickstarts.asp .net/QuickStartv20/aspnet/doc/ctrlref/data/formview.aspx[^]
You can have a look here for some FormView
example : http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/formview.aspx[^]
Works as read only, thanks :)
Works as read only, thanks :)
<![CDATA[<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Articles.aspx.cs" Inherits="Articles" %>]]>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<title>@Jon''s</title>
</head>
<body>
<form id="form1" runat="server">
<h1>@Jon''s <img src="images/sofa.jpg" alt="logo" /> </h1>
<div style="float:left;width:122px">
<p style="width: 122px; height: 663px; margin-top: 0px; margin-right: 0px;">
<a href="About.aspx">About me</a> <br />
<a href="Diary.aspx">My diary</a> <br />
<a href="Articles.aspx">Articles</a> <br />
<a href="Bookmarks.aspx">My bookmarks</a> <br />
<a href="Promotions.aspx">Promotions</a> <br />
<a href="Resume.aspx">My resume</a> <br />
<a href="Warez.aspx">Filesharing</a> <br />
</p>
</div>
<div>
<asp:calendar id="calArticles" runat="server" backcolor="White" xmlns:asp="#unknown">
BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="180px"
Width="200px" onselectionchanged="calArticles_SelectionChanged">
<selecteddaystyle backcolor="#666666" font-bold="True" forecolor="White" />
<selectorstyle backcolor="#CCCCCC" />
<weekenddaystyle backcolor="#4AA02C" />
<todaydaystyle backcolor="#CCCCCC" forecolor="Black" />
<othermonthdaystyle forecolor="#808080" />
<nextprevstyle verticalalign="Bottom" />
<dayheaderstyle backcolor="#CCCCCC" font-bold="True" font-size="7pt" />
<titlestyle backcolor="#999999" bordercolor="Black" font-bold="True" />
</asp:calendar>
<asp:formview id="Envelope" runat="server" datasourceid="SqlDataSource1" xmlns:asp="#unknown">
AllowPaging="True">
<headertemplate>
</headertemplate>
<itemtemplate>
<p> <asp:textbox runat="server" width="1000" readonly="true" id="txtSubject">Text=''<%# Eval("Subject")%>''></asp:textbox> </p>
<p> <asp:textbox runat="server" height="300" width="1000" readonly="true" id="txtBody" textmode="MultiLine">Text=''<%# Eval("EntryText") %>''></asp:textbox>
</p></itemtemplate>
</asp:formview>
<p> <asp:button id="btnFirst" runat="server" text="|<" enabled="True" xmlns:asp="#unknown" />
<asp:button id="btnPrev" runat="server" text="<<" enabled="True" xmlns:asp="#unknown" />
<asp:button id="btnNext" runat="server" text=">>" enabled="True" xmlns:asp="#unknown" />
<asp:button id="btnLast" runat="server" text=">|" enabled="True" xmlns:asp="#unknown" />
</p>
<asp:button id="btnNew" runat="server" text="New" xmlns:asp="#unknown" />
<asp:button id="btnSave" runat="server" text="Save" xmlns:asp="#unknown" />
<asp:button id="btnRefresh" runat="server" text="Refresh" xmlns:asp="#unknown" />
<asp:button id="btnDelete" runat="server" text="Delete" enabled="False" xmlns:asp="#unknown" />
<p>
<asp:textbox id="TextBox2" runat="server" width="211px" xmlns:asp="#unknown"></asp:textbox>
<asp:button id="btnSearch" runat="server" text="Search" xmlns:asp="#unknown" />
</p>
<p>
<asp:label id="lblFooter" runat="server" xmlns:asp="#unknown"></asp:label>
</p>
<asp:sqldatasource id="SqlDataSource1" runat="server" xmlns:asp="#unknown">
ConnectionString="<%
这篇关于[调试] FormView不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!