将嵌套重复器与存储过程结合使用
嘿,我想在 ASP.NET 2 中使用嵌套存储过程。
第一个存储过程返回所有营销活动,第二个存储过程返回营销活动中的所有项目。
我已经设置了 2 个中继器,现在我试图将参数从父中继器传递到子中继器存储过程,即活动 ID....这证明很棘手
在后面的代码中我想尝试
public void Repeater1_ItemDataBound(Object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
{
SqlDataSource2.SelectParameters["campaignId"].DefaultValue =
DataBinder.Eval(e.Item.DataItem, "campaignId").ToString();
}
}
但我不知道如何调用此方法或加载它,如果我尝试此操作
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnDataBinding="Repeater1_ItemDataBound">
,我收到错误
CS0123: No Heavy for 'Repeater1_ItemDataBound' matches delegate 'System.EventHandler'
任何帮助将不胜感激
编辑:将我的代码更改为
public void Repeater1_ItemDataBound(Object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
{
Response.Write(DataBinder.Eval(e.Item.DataItem, "campaignId").ToString());
SqlDataSource2.SelectParameters["campaignId"].DefaultValue =
DataBinder.Eval(e.Item.DataItem, "campaignId").ToString();
SqlDataSource2.SelectParameters["statusId"].DefaultValue =
"1";
}
foreach (RepeaterItem repeaterItem in Repeater1.Items)
{
((Repeater)(repeaterItem.FindControl("Repeater2"))).DataBind();
}
}
但没有任何喜悦它传递将活动 ID 正确存储到存储过程中,但这在前端没有正确显示,
有什么想法吗?
Hey I would like to use Nested Stored Procedures in ASP.NET 2.
The first stored procedure returns all Campains and second one returns all items in the campaigns.
I have my 2 repeaters set up, and now I am trying to pass a parameter from the parent repeater to child repeater stored procedure i.e campaign id....this proving tricky
In the code behind I wanted to try
public void Repeater1_ItemDataBound(Object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
{
SqlDataSource2.SelectParameters["campaignId"].DefaultValue =
DataBinder.Eval(e.Item.DataItem, "campaignId").ToString();
}
}
But I dont know how to call this method or get it to load if I try this
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnDataBinding="Repeater1_ItemDataBound">
I get the error
CS0123: No overload for 'Repeater1_ItemDataBound' matches delegate 'System.EventHandler'
Any help would be greatly appreciated
EDIT : Changed mY Code Behind to
public void Repeater1_ItemDataBound(Object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
{
Response.Write(DataBinder.Eval(e.Item.DataItem, "campaignId").ToString());
SqlDataSource2.SelectParameters["campaignId"].DefaultValue =
DataBinder.Eval(e.Item.DataItem, "campaignId").ToString();
SqlDataSource2.SelectParameters["statusId"].DefaultValue =
"1";
}
foreach (RepeaterItem repeaterItem in Repeater1.Items)
{
((Repeater)(repeaterItem.FindControl("Repeater2"))).DataBind();
}
}
But no joy its passing the correct campaign id to the stored procedure but this isnt displayed correctly on front end
any ideas ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Microsoft 发布了使用嵌套转发器控件显示分层数据的分步指南:显示分层数据
请记住,可以从存储过程返回两个数据集(以两个 SELECT 结尾的存储过程)
这是使用 EnterpriseLibrary 的示例
这是一个简单的嵌套转发器:
Microsoft publish an step by step guide to display hierarchical data using Nested Repeater Controls: Display Hierarchical Data
Remember that it is posible to return two datasets from a Store Procedure (An store procedure that ends with two SELECTs)
This is an example using EnterpriseLibrary
This is a simple nested repeater:
您不应尝试附加
DataBinding
事件,而应附加ItemDataBound
事件:DataBinding
事件适用于整个中继器,>ItemDataBound
将针对每个项目触发。Instead of trying to attach the
DataBinding
event, you should be attaching theItemDataBound
event:The
DataBinding
event is for the whole repeater, theItemDataBound
will fire per item.