Click here to Skip to main content
15,847,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I run this code, I'm having this problem, because when I select a different date from the calendar control (Articles.aspx), even though the data should be refreshed within the formview it does not refresh. It is connected to an SQL Data Source, and, from Visual Studio it seems that the SQL Statement is being updated, however, I must be missing something out.

   <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:formview id="Envelope" runat="server" datasourceid="SqlDataSource1" xmlns:asp="#unknown">
        <p> <asp:textbox runat="server" width="1000" readonly="false" id="txtSubject" text="<%# Eval("Subject")%>"></asp:textbox> </p>
        <p> <asp:textbox runat="server" height="300" width="1000" readonly="false" id="txtBody" textmode="MultiLine" text="<%# Eval("EntryText") %>"></asp:textbox> 
             <asp:button id="btnNew" runat="server" text="New" commandname="New" />
             <asp:button id="btnEdit" runat="server" text="Edit" commandname="Edit" />
             <asp:button id="btnSave" runat="server" text="Save" commandname="Update" />
             <asp:button id="btnCancel" runat="server" text="Cancel" commandname="Cancel" />           
             <asp:button id="btnRefresh" runat="server" text="Refresh" />
             <asp:button id="btnDelete" runat="server" text="Delete" enabled="False" />
    <asp:textbox id="TextBox2" runat="server" width="211px" xmlns:asp="#unknown"></asp:textbox>
    <asp:button id="btnSearch" runat="server" text="Search" xmlns:asp="#unknown" />
    <asp:label id="lblFooter" runat="server" xmlns:asp="#unknown"></asp:label>
<asp:sqldatasource id="SqlDataSource1" runat="server" xmlns:asp="#unknown">
        ConnectionString="<%$ ConnectionStrings:couch_dbConnectionString %>" 
        SelectCommand="SELECT [Timestamp], [Subject], [EntryText] FROM [Article]"></asp:sqldatasource>

public partial class Articles : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        this.Title = "Jon's Couch";
    protected void calArticles_SelectionChanged(object sender, EventArgs e)
            SqlDataSource1.SelectCommand = 
            System.String.Concat("SELECT [Timestamp], [Subject], [EntryText] FROM [Article] WHERE [Timestamp] >= '" +
            calArticles.SelectedDate.ToString() + "' AND [Timestamp] < (DATEADD(day, 1, [Timestamp]));");

When I select 'Edit' or 'Add' the textboxes simply disappear, whilst when I select Save, this error is displayed:
FormView 'Envelope' must be in edit mode to update a record.

Screendumps here illustrate the issues.

Updated 29-Aug-10 0:23am
jon-80 28-Aug-10 14:39pm    
NOTE: Rendering of this code is unclear...

1 solution

The most likely issue, regardless of the uselessness of the code provided, is that you update your database in your event, and bind it in page load, which means it binds BEFORE it is updated. Binding should occur in prerender.
Share this answer
jon-80 28-Aug-10 23:42pm    
lol, while thanking you for your comment, are you suggesting that I bind the data connection (say as per this article -, and, that I discard the datasource from the designer.

Any idea why Formview does not work, and, I think it is bound (somehow) because otherwise the data wouldn't appear on the form... just my logic...

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