Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

XML
<%@ 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" />
    &nbsp;<asp:Button ID="btnPrev" runat="server" Text="<<" Enabled="True" />
    &nbsp;<asp:Button ID="btnNext" runat="server" Text=">>" Enabled="True" />
    &nbsp;<asp:Button ID="btnLast" runat="server" Text=">|" Enabled="True" />
    </p>
    <asp:Button ID="btnNew" runat="server" Text="New" />
    &nbsp;<asp:Button ID="btnSave" runat="server" Text="Save" />
    &nbsp;<asp:Button ID="btnRefresh" runat="server" Text="Refresh" />
    &nbsp;<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>


I have checked the SQL Statement generated within VS 2008 on SQL Server 2005 Management Studio and it works fine.
SQL
SELECT [Timestamp], [Subject], [EntryText]
FROM [Article] WHERE [Timestamp] >= '8/27/2010 12:00:00 AM' AND
[Timestamp] < (DATEADD(day, 1, [Timestamp]));


SQL Result
MSIL
2010-08-28 00:00:00.000 subject test
2010-08-28 00:00:00.000 subject 2   test 2


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:
Posted
Updated 28-Aug-10 4:54am
v5

FormView is actually a Template based control (That means, you have to define which field to bind to which control inside the itemtemplate element.

I didn't run your code, but as I can see, you are not binding your TextBox controls (Inside the FormView's ItemTemplate section) with any data using the Bind() 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 the EntryText field)
<asp:TextBox runat="server" Width="1000" Text='<%# Bind("EntryText") %>' ReadOnly="true" ID="txtSubject"></asp:TextBox>


You can have a look here for some FormView example : http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/formview.aspx[^]
 
Share this answer
 
v2
Comments
jon-80 28-Aug-10 13:19pm    
10x
jon-80 28-Aug-10 13:28pm    
thanks for that; I did try some code but somehow it's not binding..


<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>
</ItemTemplate>
</asp:FormView>


I'll go through the article again and see if anything else makes sense :)
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="<%$ ConnectionStrings:couch_dbConnectionString %>" 
        SelectCommand="SELECT [Timestamp], [Subject], [EntryText] FROM [Article]"></asp:sqldatasource>
</div>
</form>
</body>
</html>
 
Share this answer
 
v2
Comments
Al-Farooque Shubho 28-Aug-10 13:54pm    
It should also work without the readonly="true" property.
jon-80 28-Aug-10 14:16pm    
yeh, I'm still trying to figure out how to Edit, Save and Refresh the controls, because the textboxes are disappearing when I tried Editing...guess I need more research :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900