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 ?
Instead of trying to attach the DataBinding
event, you should be attaching the ItemDataBound
event:
<asp:Repeater ID="Repeater1" runat="server"
DataSourceID="SqlDataSource1" OnItemDataBound="Repeater1_ItemDataBound">
The DataBinding
event is for the whole repeater, the ItemDataBound
will fire per item.