在输入值更改时更新中继器
Updating Repeater on inputed value change
所以我创建了弹出编辑表单,我也想在此弹出窗口中显示连接的行。为此,我将 Repeater 与数据源一起使用,并在用户每次打开编辑表单时更新数据源 select 命令:
编辑表单初始化:
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 的回调并使用新日期更新会话值:
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' 的 public 属性”
解决方案是使用列表数据源并在每次请求时更新它
repeater.DataSource = resources.Count() == 0 ? null : resources;
repeater.DataBind();
所以我创建了弹出编辑表单,我也想在此弹出窗口中显示连接的行。为此,我将 Repeater 与数据源一起使用,并在用户每次打开编辑表单时更新数据源 select 命令:
编辑表单初始化:
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 的回调并使用新日期更新会话值:
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' 的 public 属性”
解决方案是使用列表数据源并在每次请求时更新它
repeater.DataSource = resources.Count() == 0 ? null : resources;
repeater.DataBind();