[debug] doe未与数据源绑定 [英] [debug] doe s not bind with data source

查看:74
本文介绍了[debug] doe未与数据源绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行此代码时,我遇到了这个问题,因为当我从日历控件(Articles.aspx)中选择一个不同的日期时,即使应该在formview中刷新数据,它也不会刷新.它已连接到SQL数据源,并且从Visual Studio中似乎正在更新SQL语句,但是,我必须缺少某些内容.

Articles.aspx

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.

Articles.aspx

<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>
        <edititemtemplate>
        <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> 
        <p> 
             <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" />
        </p>
        </p>
        </edititemtemplate>
        </asp:formview>
<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>



Articles.aspx.cs



Articles.aspx.cs

public partial class Articles : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "Jon''s Couch";
        Envelope.DataBind();
    }
    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]));");
            Envelope.DataBind();
           
    }



当我选择编辑"或添加"时,文本框将消失,而当我选择保存"时,将显示此错误:
FormView信封"必须处于编辑模式才能更新记录.
:confused:

屏幕转储



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.
:confused:

Screendumps here illustrate the issues.

:confused:

推荐答案

ConnectionStrings:couch_dbConnectionString%> SelectCommand ="SELECT [Timestamp],[Subject],[EntryText] FROM [Article]"></asp:sqldatasource> </div>
ConnectionStrings:couch_dbConnectionString %>" SelectCommand="SELECT [Timestamp], [Subject], [EntryText] FROM [Article]"></asp:sqldatasource> </div>



Articles.aspx.cs



Articles.aspx.cs

public partial class Articles : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "Jon''s Couch";
        Envelope.DataBind();
    }
    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]));");
            Envelope.DataBind();
           
    }



当我选择编辑"或添加"时,文本框将消失,而当我选择保存"时,将显示此错误:
FormView信封"必须处于编辑模式才能更新记录.
:confused:

屏幕转储



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.
:confused:

Screendumps here illustrate the issues.

:confused:


无论提供的代码是否有用,最有可能出现的问题是,您在事件中更新数据库并将其绑定到页面加载中,这意味着它在绑定之前它已更新.绑定应该在预渲染中进行.
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.


这篇关于[debug] doe未与数据源绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆