问题描述
因此,我创建了弹出窗口“编辑”表单,并且我也想在此弹出窗口中显示连接的行。为此,我在数据源中使用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'的公共属性”
解决方法
解决方案是使用List数据源并在每次请求时对其进行更新
repeater.DataSource = resources.Count() == 0 ? null : resources;
repeater.DataBind();