【问题标题】:ControlParameter is returning previous value?ControlParameter 正在返回以前的值?
【发布时间】:2016-01-07 19:41:19
【问题描述】:

我正在尝试创建主/详细视图。我的DetailsView 在其自己的页面上正常工作,我的GridView 显示我的EquipmentDataSource 也正常工作。我可以使用FilterParamaters 过滤GridView

<FilterParameters>
    <%-- ControlParameter.Name will String.Formatted with the control's value --%>
    <asp:ControlParameter Type="String" Name='eEquipment.Contains("{0}")' ControlID="txtNumber" PropertyName="Text" />
</FilterParameters>

(我理解动态 Linq 表达式,因为控件名称设计不好)

当我尝试根据DetailsView 显示的项目的键进行过滤时,问题就出现了。如果我切换到 PO# 为 123 的项目,然后是 456,ControlParameter 将评估为 123。我认为它可能是从 ViewState 获取值而不是控件当前具有的值,但我不知道为什么。

代码:

<cc:ProcurementDataSource ID="dsProcurements" runat="server" />
<asp:DetailsView ID="dtvProcurements" runat="server" AllowPaging="True" DataSourceID="dsProcurements" />
<cc:EquipmentDataSource ID="dsEquipment" runat="server">
    <FilterParameters>
        <asp:ControlParameter Type="String" Name='ePO == "{0}"' ControlID="dtvProcurements" PropertyName="DataItem.epClientPO" />
    </FilterParameters>
</cc:EquipmentDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="dsEquipment" />

我正在通过Page_Load 致电Page.DataBind()。我尝试在每个控件上手动调用DataBind(),以防它以奇怪的顺序发生,但这似乎没有帮助。

【问题讨论】:

    标签: c# asp.net gridview webforms


    【解决方案1】:

    我似乎对Control.DataBind() 是否被阻止感到困惑。

    protected void Page_Load(object sender, EventArgs e)
    {
        AutoMapperConfiguration.Initialize();
        dtvProcurements.DataBind();
        GridView1.DataBind();
    }
    

    这样做时无法正常工作:

    protected void Page_Load(object sender, EventArgs e)
    {
        AutoMapperConfiguration.Initialize();
        dtvProcurements.DataBind();
    }
    
    protected void dtvProcurements_DataBound(object sender, EventArgs e)
    {
        GridView1.DataBind();
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-06
      • 1970-01-01
      相关资源
      最近更新 更多