Asp.net 如何调试中继器控件?
是否可以在以下位置设置aspx用户控件页面的html断点 (例如,此处给出的代码):Asp.net 如何调试中继器控件?,asp.net,repeater,Asp.net,Repeater,是否可以在以下位置设置aspx用户控件页面的html断点 (例如,此处给出的代码): (此处中断) 我正在使用Visual Studio 2008。 我知道我可以在调试模式下查看绑定到repeater控件的dataview,但我更希望看到这种情况,因为在某些情况下,当强制转换无法正常工作时,我会遇到错误。所以我想我是在问我们是否可以进入并“查看”正在运行的循环中的Container.DataItem值 非常感谢,John不,您无法调试设计视图。 OnItemDataBound可用于在代码隐
(此处中断)
我正在使用Visual Studio 2008。我知道我可以在调试模式下查看绑定到repeater控件的dataview,但我更希望看到这种情况,因为在某些情况下,当强制转换无法正常工作时,我会遇到错误。所以我想我是在问我们是否可以进入并“查看”正在运行的循环中的
Container.DataItem
值
非常感谢,John不,您无法调试设计视图。
OnItemDataBound可用于在代码隐藏中进行调试。您可以在代码隐藏文件中的repeater控件上为
ItemDataBound
添加事件处理程序
在传递的RepeaterItemEventArgs
中,您可以访问e.Item.DataItem
,它与代码中的容器.DataItem相同。然后,使用调试器的即时窗口可以测试这些值
例如:
Page.ascx
<asp:Repeater runat="server" ID="Repeater1" OnItemDataBound="Repeater1_Databound">
...
</asp:Repeater>
使用中继器的-事件。在那里交换数据绑定,就可以调试codebehind中的值。
<asp:Repeater runat="server" ID="Repeater1" OnItemDataBound="Repeater1_Databound">
...
</asp:Repeater>
protected void Repeater1_Databound(object sender, RepeaterItemEventArgs e)
{
// Breakpoint here - use immediate window or
// watch to examine contents of the 'item' variable.
var item = e.Item.DataItem;
}