How to set expand collapse functionality in code behind dynamically generated rows? Please suggest me how can i implement this
<pre><code>SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite Osite = new SPSite(SPContext.Current.Site.Url))
                    {
                        using (SPWeb oWeb = Osite.OpenWeb())
                        {
                            Olist = oWeb.Lists["ImageList"];
                            SPListItemCollection oitems = Olist.GetItems();
                            SPFieldChoice category_field = (SPFieldChoice)Olist.Fields["category"];
                            int i = 0;
                            foreach (string str in category_field.Choices)
                            {
                                TableCell cell_inputA = new TableCell();
                                TableCell cell_inputB = new TableCell();
                                TableRow rowHeading = new TableRow();
                                rowHeading.ID = "trGrpHeader2";
                                TableRow rowAlbum = new TableRow();
                                rowAlbum.ID = "row1";
                                cell_inputA.Text = str;
                                cell_inputA.Attributes.Add("onClick", "true javascript:Toggle_trGrpHeader2('rowAlbum');");
                                rowHeading.Cells.Add(cell_inputA);

                            SPQuery query = new SPQuery();
                            query.Query = "&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name='category' /&gt;&lt;Value Type='Choice'&gt;" + str + "&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;";

                            DataTable tempTbl = Olist.GetItems(query).GetDataTable();
                            if (tempTbl != null)
                            {
                                DataView v = new DataView(tempTbl);
                                DataTable tbl = v.ToTable(true, "Album");
                                int a = tbl.Rows.Count;
                                int j = 0;


                                for (j = 0; j &lt; tbl.Rows.Count; j++)
                                {
                                    String albumName = tbl.Rows[j][0].ToString();




                                    SPQuery objQuery = new SPQuery();
                                    objQuery.Query = "&lt;Where&gt;&lt;And&gt;&lt;Eq&gt;&lt;FieldRef Name='category' /&gt;&lt;Value Type='Choice'&gt;" + str + "&lt;/Value&gt;&lt;/Eq&gt;&lt;Eq&gt;&lt;FieldRef Name='Album' /&gt;&lt;Value Type='Choice'&gt;" + albumName + "&lt;/Value&gt;&lt;/Eq&gt;&lt;/And&gt;&lt;/Where&gt;";
                                    SPListItemCollection oitem = Olist.GetItems(objQuery);


                                    foreach (SPListItem item in oitem)
                                    {

                                        if (item["Album Cover"].ToString() == "True")
                                        {
                                            albumcount++;
                                            lblheading = new Label();

                                            if (albumcount &lt; 5)
                                            {
                                                lblheading.Text = "&amp;nbsp;&amp;nbsp;";
                                            }
                                            else
                                            {
                                                lblheading.Controls.Add(new                 LiteralControl("&lt;br/&gt;"));
                                                albumcount = 0;
                                            }
                                            // LinkButton linkbtn = new LinkButton();
                                            ImageButton imgbtn = new ImageButton();
                                            imgbtn.ID = "pg" + i;

                                            imgbtn.PostBackUrl = "/_layouts/CL_categorize_Image_Gallery/CL_GridViewImage.aspx?" + "category_field=" + str + "&amp;album=" + albumName;
                                            imgbtn.ImageUrl = Osite.Url + "/" + Olist.ToString() + "/" + item["Name"].ToString();
                                            urlimage = Osite.Url + "/" + Olist.ToString() + "/" + item["Name"].ToString();
                                            imgbtn.Width = 100;
                                            imgbtn.Height = 100;
                                            imgbtn.Attributes.Add("target", "_blank");

                                            imgbtn.EnableViewState = true;
                                            // dr["ListImage"] = imgbtn.ImageUrl;
                                            //dr["ListImage"] = "&lt;asp:ImageButton ID=Image runat=server ImageUrl=" + Osite.Url + "/" + Olist.ToString() + "/" + item["Name"].ToString() + " /&gt;";

                                            cell_inputB.Controls.Add(imgbtn);
                                            cell_inputB.Controls.Add(lblheading);
                                            rowAlbum.Cells.Add(cell_inputB);

                                        }
                                        else
                                        {

                                       }
                                    }
                                }
                            }
                            i++;
                            tblInputs.Rows.Add(rowHeading);
                            tblInputs.Rows.Add(rowAlbum);
                       }               
                    }
                }
            });
</code></pre>
