输入值变更时更新中继器

时间:2020-09-01 13:38:07

标签: c# asp.net webforms devexpress

因此,我创建了弹出窗口“编辑”表单,并且我也想在此弹出窗口中显示连接的行。为此,我在数据源中使用Repeater并更新数据源,每次用户打开“编辑”表单时选择comand:

编辑表单的初始化:

   case "Edit":
   {
         var sourceKeyValue = DataUtils.GetInt64(grid.GetRowValues(e.VisibleIndex, grid.KeyFieldName));
         var resource = worker.ResourcePlanningViews.First(rpv => rpv.ID == sourceKeyValue);
         Session["VisibleIndex"] = e.VisibleIndex;
         Session["DateFrom"] = resource.DateFrom;
         Session["DateTo"] = resource.DateTo;
         this.userPlanings.SelectCommand = string.Format(@"Select [T0].id,
                            DateFrom, DateTo, 
                            [T0].Description, 
                            [T1].Name AS Project,
                            [T2].Name AS Company,
                            [T0].BookingPercentage
                            from[dbo].[WP_Topic_ResourcePlanning] as [T0]
                            Join WP_BaseData_Project as [T1] on[T0].ProjectID = [T1].id
                            Join WP_BaseData_Company as [T2] on[T1].CompanyID = [T2].id
                            where UserID in (
                            SELECT UserID
                              FROM[dbo].[WP_Topic_ResourcePlanning]
                                where id = {0})
                              and[T0].id != {0}
                              and (
                                [T0].DateFrom BETWEEN (@DateFrom) and (@DateTo)
                                or 
                                [T0].DateTo BETWEEN (@DateFrom) and (@DateTo))", resource.ResourcePlanningId);
                        grid.StartEdit(e.VisibleIndex);
                    }

数据源:

 <asp:SqlDataSource ID="userPlanings" runat="server" ConnectionString="<%$ ConnectionStrings:WebPortalConnectionString %>">
        <SelectParameters>
            <asp:SessionParameter Name="DateFrom" SessionField="DateFrom" DefaultValue="2/22/2012" Type="String" />
            <asp:SessionParameter Name="DateTo" SessionField="DateTo" DefaultValue="7/22/2020" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>

在编辑表单中的值更改后,我想更新pupup中的转发器,为此,我试图处理来自ASPxCallbackPanel的回调并使用新日期更新Session值:

protected void HandleDateTimeCallback(object sender, CallbackEventArgsBase e)
    {
        var gridCntrl = this.gridResourcePlanningsCtrl.GridControl;
        var callbackPanel = (ASPxCallbackPanel)gridCntrl.FindEditFormTemplateControl("editFormPanelCtrl");
        int visibleIndex = (int)Session["VisibleIndex"];

        var sourceKeyValue = DataUtils.GetInt64(gridCntrl.GetRowValues(visibleIndex, gridCntrl.KeyFieldName));
        var resource = worker.ResourcePlanningViews.First(rpv => rpv.ID == sourceKeyValue);

        var dateFrom = (DateTime)this.GetCtrlValue("dtDateFrom", callbackPanel);
        var dateTo = (DateTime)this.GetCtrlValue("dtDateTo", callbackPanel);
        Session["DateFrom"] = dateFrom;
        Session["DateTo"] = dateTo;

        gridCntrl.StartEdit(visibleIndex);

    }

它不起作用。 当我尝试使用gridCntrl.StartEdit(visibleIndex)时出现错误消息:

System.InvalidOperationException: 'Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.'

我还试图使用更新面板,但是服务器出现错误“类型'System.Web.UI.UpdatePanel'没有名为'Repeater'的公共属性”

1 个答案:

答案 0 :(得分:0)

解决方案是使用List数据源并在每次请求时对其进行更新

  repeater.DataSource = resources.Count() == 0 ? null : resources;
  repeater.DataBind();
相关问题