I have an user control page i.e. template(.ascx) where in I have a repeater which gets loaded by executing a stored procedure. There is also a parent page which has its own repeater along with a button on each row and this repeater too gets loaded with the execution of the stored procedure.
Now, the button on each row of the parent repeater, when that gets clicked first two column values of that particular rows (Eg: G6300 and Group Term Ife Insurance) needs to be passed to the stored procedure present in the template where the child repeater exists and child repeater should be visible.
Till now, I am successful in displaying the parent repeater, passing that particular row values on the button click to the child stored procedure and also successful in getting the results in list by executing the child stored procedure. But when I try to assign this list to the child repeater present on template page it gives an exception for the child repeater (System.NullReferenceException: Object reference not set to an instance of an object).
I am guessing I am missing initializing the child repeater and hence it is null. But not completely positive about it and also about the solution.
Please suggests something.
//Template code (Inner Repeater)
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
return;
}
}
public void LoadRepeater(string id, string policyNo, string desc) //gets called from parent repeater
{
//Loading the tempalte
StringBuilder template1 = MembershipRepository.LoadPolicyDetailsTemplate("PolicyDetailsTemplate1.ascx");
CustomerPortalWebContentEntities context = new CustomerPortalWebContentEntities();
RetrievePolicyDetails policyDetails = new RetrievePolicyDetails();
List<PolicyDetails> polDetails = policyDetails.GetPolicyDetails(id, policyNo, desc); //polDetails HAS ALL THE REQUIRED ROWS
rptPolicyDetails.DataSource = polDetails; //EXCEPTION ON THIS LINE
rptPolicyDetails.DataBind();
}
//Button click event for each row on Parent page(parent repeater), where the template/child repeater is getting called
protected void rptCoverage_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "CoverageDetails")
{
//Button was clicked
var policy = e.Item.FindControl("lblPolicyNo") as Label;
var description = e.Item.FindControl("lblDescription") as Label;
var idPerson = id_person;
var placeHolder = e.Item.FindControl("UCPlaceHolder") as Control;
placeHolder.Controls.Add((PolicyDetailsTemplate1)Page.LoadControl("~/Shared/Controls/PolicyDetailsTemplate1.ascx"));
//this.placeHolder.Controls.Add((PolicyDetailsTemplate1)Page.LoadControl("~/Shared/Controls/PolicyDetailsTemplate1.ascx"));
//calling the specific tempalte with specific sp /**/ will change w.r.t multiple templates
PolicyDetailsTemplate1 template = new PolicyDetailsTemplate1();
template.LoadRepeater(idPerson, policy.Text.Trim(), description.Text.Trim());
}
}
//Here is the snippet of the output