本文介绍了这是一个FormView错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个FormView(启用了分页)绑定到ASP.NET页面上的LinqDataSource。我遇到一些非常怪异的行为,并不能找出为什么它的发生。有关这个问题的简单起见,我已删除一些不需要code(其他FormView控件模板等)来演示此行为。

I have a FormView (with paging enabled) that is bound to a LinqDataSource on an ASP.NET page. I'm experiencing some very weird behavior and can't figure out why it's happening. For simplicity sake on this question I have removed some unneeded code (other FormView templates, etc) to demonstrate this behavior.

我FormView的有3场,两个文本框和一个DropDownList的。将DropDownList绑定到页面上的其他的LinqDataSource并包含外键值。当FormView的使用LinqDataSource只包含一个记录,我尝试更新它,的更新失败,​​因为DropDownList的选定值始终为空的,不管我选择它的参数值。当FormView的使用LinqDataSource包含2个或更多的记录,它的作品,因为它应该。

My FormView has 3 fields, two textboxes and one DropDownList. The DropDownList is bound to another LinqDataSource on the page and contains foreign key values. When the FormView's LinqDataSource only contains one record and I try to update it, the update fails because the selected value of the DropDownList is always empty, no matter which value I pick for it. When the FormView's LinqDataSource contains 2 or more records, it works as it should.

现在这里是真正奇怪的事情。更新实际上是失败,因为FormView的PagerSettings的!当我只使用默认设置寻呼机,一切都很好。当我改变PagerMode为下一步previousFirstLast ,更新失败。

Now here's the really weird thing. The update is actually failing because of the FormView's PagerSettings! When I use just the default Pager settings, all is well. When I change the PagerMode to NextPreviousFirstLast, the update fails.

下面是我用它FormView的数据源:

Here's my FormView with it's data sources:

<asp:FormView ID="fvData" runat="server" AllowPaging="True"
    DataKeyNames="ID" DataSourceID="ldsData" DefaultMode="Edit">
    <EditItemTemplate>
        <table class="pad5">
            <tr>
                <td class="field-name">AREA:</td>
                <td>
                    <asp:DropDownList ID="cboAREA" runat="server" DataTextField="AREA_NAME"
                        DataValueField="AREA1" SelectedValue='<%# Bind("AREA") %>' DataSourceID="ldsAreas" />
                </td>
            </tr>
            <tr>
                <td class="field-name">LOOP:</td>
                <td><asp:TextBox ID="txtLOOP" runat="server" Text='<%# Bind("LOOP") %>' /></td>
            </tr>
            <tr>
                <td class="field-name">LOOP DESCRIPTION:</td>
                <td><asp:TextBox ID="txtLOOP_DESCRIPTION" runat="server"
            Text='<%# Bind("LOOP_DESCRIPTION") %>' style="width: 600px" /></td>
            </tr>
        </table>

        <asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" CausesValidation="True" />
        <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="False" />
    </EditItemTemplate>
    <PagerSettings Mode="NextPreviousFirstLast"
        FirstPageText="&amp;lt;&amp;lt; First" LastPageText="Last &amp;gt;&amp;gt;"
        NextPageText="Next &amp;gt;" PreviousPageText="&amp;lt; Prev"
        Position="TopAndBottom" />
    <PagerStyle CssClass="pager" />
</asp:FormView>

<asp:LinqDataSource ID="ldsData" runat="server"
    ContextTypeName="E_and_I.EAndIDataDataContext" EnableDelete="True"
    EnableInsert="True" EnableUpdate="True" EntityTypeName=""
    TableName="INSTRUMENT_LOOP_DESCRIPTIONs" onselecting="ldsData_Selecting" OrderBy="ID ASC" >
</asp:LinqDataSource>

<asp:LinqDataSource ID="ldsAreas" runat="server"
    ContextTypeName="E_and_I.EAndIDataDataContext" EntityTypeName=""
    TableName="AREAs" onselecting="ldsAreas_Selecting">
</asp:LinqDataSource>

和这里是我的两个使用LinqDataSource的选择事件:

And here's both of my LinqDataSource's Selecting events:

EAndIDataDataContext db = new EAndIDataDataContext();

protected void ldsData_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
    e.Result = db.INSTRUMENT_LOOP_DESCRIPTIONs.Take(1); // we only want one record for testing
}

protected void ldsAreas_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
    e.Result = db.AREAs.OrderBy(a => a.AREA1).Select(a => new { AREA1 = a.AREA1, AREA_NAME = "(" + a.AREA1 + ") " + a.AREA_NAME });
}

我已经追踪到问题源于这些行:

I've traced the problem to these lines:

<PagerSettings Mode="NextPreviousFirstLast"
    FirstPageText="&amp;lt;&amp;lt; First" LastPageText="Last &amp;gt;&amp;gt;"
    NextPageText="Next &amp;gt;" PreviousPageText="&amp;lt; Prev"
    Position="TopAndBottom" />

当我删除上述 PagerSettings 元素,FormView控件更新记录就好了!有谁知道为什么地狱寻呼机设置将有什么关系呢?我使用.NET Framework 4.0。

As soon as I remove the above PagerSettings element, the FormView updates the record just fine! Does anybody know why the hell the pager settings would have anything to do with this? I'm using the .NET Framework 4.0.

推荐答案

我复制你的code的一部分,我做了一个实验,我想,我尝试相同的行为。

I copied part of your code and I made an experiment and I think, I'm experimenting the same behavior.

这是我做过什么:

<asp:LinqDataSource runat="server" ID="lds"
    TableName="jobs" ContextTypeName="WebApplication2.DataAccess.PubsDataContext" >

</asp:LinqDataSource>
<asp:LinqDataSource runat="server" ID="ldse"
    TableName="employee" ContextTypeName="WebApplication2.DataAccess.PubsDataContext" OnSelecting="ldse_Selecting">

</asp:LinqDataSource>

<asp:FormView runat="server" DefaultMode="Edit" ClientIDMode="Predictable" DataKeyNames="emp_id" DataSourceID="ldse"
    AllowPaging="true" OnItemCommand="Unnamed_ItemCommand" ID="formView">
    <EditItemTemplate>
        <div>
            <asp:DropDownList runat="server" ID="ddlJobs" DataSourceID="lds" DataTextField="job_desc" DataValueField="job_id">
            </asp:DropDownList>
        </div>
        <div>
            <asp:TextBox runat="server" TextMode="MultiLine" ID="txtDesc" />
        </div>
        <div>
            <asp:Button Text="Save" runat="server" CommandName="Save" CausesValidation="true" />
            <asp:Button Text="Cancel" runat="server" CommandName="Cancel" CausesValidation="false" />
        </div>
    </EditItemTemplate>
    <PagerSettings Mode="NextPreviousFirstLast"
        FirstPageText="&amp;lt;&amp;lt; First" LastPageText="Last &amp;gt;&amp;gt;"
        NextPageText="Next &amp;gt;" PreviousPageText="&amp;lt; Prev"
        Position="TopAndBottom" />

这是我的意见:


  • 如果在 FormView控件 只包含一行,,然后在 FormView控件怪异的行为和预期我的命令不工作。

  • If the FormView contains only one row, then the FormView behaves weird and my commands do not work as expected.


  • 我的保存命令从来没有发射,而不是'取消命令被触发

  • My Save command is never fired, instead the `Cancel command is fired

我的取消命令导致我的 FormView控件消失...

My Cancel command causes my FormView to disappear...

首先,我想这是因为&放大器;放大器; 字符,但这是不是这样

First I thought this was because of the &amp; characters, but this is not the case

我收窄问题位置=TopAndBottom


  • 如果您设置了位置属性为:


  • Top

TopAndBottom

TopAndBottom

您尝试同样的问题。 (正如你提到可能是一个错误)

You will experiment the same problem. (As you mention probably a bug)

如果您设置了位置属性为:


  • BUTTOM

据按预期工作

要说句实话,如果这是一个错误,我不能相信没有别的发现并报告。

To be honest, if this is a bug, I can't believe none else has found it and report it.

我做了与Visual Studio 2012相同的实验网络(ASP.NET 4.5),我尝试了完全相同的行为...

I made the same experiment with Visual Studio 2012 for Web (ASP.NET 4.5) and I'm experimenting the exact same behavior...

这让我觉得,也许我做的东西基本上是错误的,也许这是不是一个错误,这就是为什么我尝试用两个版本的ASP.NET 4和ASP.NET 4.5相同的行为,但如果是这样的的情况下,我根本无法弄清楚它是什么。

This makes me think that probably I'm doing something fundamentally wrong and perhaps this is not a bug and that's why I'm experimenting the same behavior with both versions ASP.NET 4 and ASP.NET 4.5, but if that's the case, I simply can't figure out what is it.

在另一方面,如果这是一个错误,在同样的bug将在ASP.NET 4.5 present

On the other hand, if this is a bug, the same bug will be present in ASP.NET 4.5

我上传了code到我的GitHub网站参考

这篇关于这是一个FormView错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 01:56
查看更多