You need to bind the inner repeater inside outer repeater's ItemDtatBound event.
I would change the markup to add the event method:
<asp:Repeater ID="MyRepeater" runat="server" OnItemDataBound="MyRepeater_ItemDataBound">
In page_load I would call a method to databind the outer repeater:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadMyRepeater();
}
}
private void LoadMyRepeater()
{
string filename = this.Parent.Page.Title;
Label parLbl = (Label)Parent.FindControl("Label1");
if (parLbl != null)
{
Labelpart.Text = parLbl.Text;
}
string b = Labelpart.Text;
string part = b;
string fam = b.Substring(0, 2);
Labelfam.Text = fam;
string act = b.Substring(4, 2);
Labelact.Text = act;
string switches = b.Substring(2, 2);
Labelswitch.Text = switches;
string switch02 = "02";
string switch03 = "03";
string switch11 = "11";
string switch12 = "12";
string str = "SELECT [ID], [ProductName] FROM [bvc_Product] WHERE (([ProductName] LIKE '%' + @param1 + '%') AND ([ProductName] LIKE '%' + @param2 + '%') AND ([ProductName] NOT LIKE '%' + @param3 + '%') AND (([ProductName] LIKE '%' + @param4 + '%') OR ([ProductName] LIKE '%' + @param5 + '%') OR ([ProductName] LIKE '%' + @param6 + '%') OR ([ProductName] LIKE '%' + @param7 + '%') OR ([ProductName] LIKE '%' + @param8 + '%')))";
SqlConnection con = new SqlConnection(connectionStrings);
SqlCommand cmd = new SqlCommand(str, con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@param1", fam);
cmd.Parameters.AddWithValue("@param2", act);
cmd.Parameters.AddWithValue("@param3", part);
cmd.Parameters.AddWithValue("@param4", switches);
cmd.Parameters.AddWithValue("@param5", switch02);
cmd.Parameters.AddWithValue("@param6", switch03);
cmd.Parameters.AddWithValue("@param7", switch11);
cmd.Parameters.AddWithValue("@param8", switch12);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
MyRepeater.DataSource = rdr;
MyRepeater.DataBind();
con.Close();
}
Now in outer repeater's IemDataBound event I would find the inner repeater from item and bind it:
protected void MyRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string ID = e.Item.FindControl("lblID").ToString();
System.Web.UI.WebControls.Repeater rpt = (System.Web.UI.WebControls.Repeater)e.Item.FindControl("NestedRepeater");
string str = "SELECT [ID], [ProductName] FROM [bvc_Product] WHERE (([ProductName] LIKE '%' + @param1 + '%') AND ([ProductName] LIKE '%' + @param2 + '%') AND ([ProductName] NOT LIKE '%' + @param3 + '%') AND (([ProductName] LIKE '%' + @param4 + '%') OR ([ProductName] LIKE '%' + @param5 + '%') OR ([ProductName] LIKE '%' + @param6 + '%') OR ([ProductName] LIKE '%' + @param7 + '%') OR ([ProductName] LIKE '%' + @param8 + '%')))";
SqlConnection con = new SqlConnection(connectionStrings);
if(rpt!= null)
{
string str2 = "SELECT [PropertyID], [PropertyValue] FROM [bvc_ProductPropertyValue] WHERE [ProductID] = @param9";
SqlCommand cmd2 = new SqlCommand(str2, con);
cmd2.CommandType = CommandType.Text;
cmd2.Parameters.AddWithValue("param9", ID);
con.Open();
SqlDataReader rdr2 = cmd2.ExecuteReader();
rpt.DataSource = rdr2;
rpt.DataBind();
con.Close();
}
}
}
Hope it helps!