private void LoadDanhMuc() { try { NhomSanPham nhomsanpham = new NhomSanPham(); DataSet ds = nhomsanpham.SelectAll(); ds.Tables[0].DefaultView.Sort = "SapXep ASC"; //Table tbl = new Table(); // tbl.CssClass = "ListCat"; if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { if (dr["NhomChaID"].ToString() == "" || dr["NhomChaID"].ToString() == "0") { HtmlTableRow tbr = new HtmlTableRow(); //tbr.Style.Add("margin", "0"); //tbr.Style.Add("padding", "0"); //tbr.Style.Add("padding", "0"); HtmlTableCell tbc1 = new HtmlTableCell(); HtmlTableCell tbc2 = new HtmlTableCell(); //image cells HtmlTableCell tbc3 = new HtmlTableCell(); HtmlTableCell tbc4 = new HtmlTableCell(); HtmlTableCell tbc5 = new HtmlTableCell(); tbc1.Style.Add("width", "3%"); tbc2.InnerText = dr["SapXep"] + "." + dr["TenNhomSanPham"]; tbc2.ColSpan = 2; tbc3.Style.Add("width", "16px"); tbc4.Style.Add("width", "16px"); tbc5.Style.Add("width", "16px"); tbc3.Style.Add("padding", "0"); tbc3.Style.Add("margin", "0"); tbc3.Style.Add("cursor", "hand"); tbc4.Style.Add("padding", "0"); tbc4.Style.Add("margin", "0"); tbc4.Style.Add("cursor", "hand"); tbc5.Style.Add("padding", "0"); tbc5.Style.Add("margin", "0"); tbc5.Style.Add("cursor", "hand"); HtmlImage img1 = new HtmlImage(); HtmlImage img2 = new HtmlImage(); HtmlImage img3 = new HtmlImage(); img1.Src = "../images/edit.gif"; img2.Src = "../images/delete.gif"; img3.Src = "../images/add.gif"; img1.Alt = "Sửa danh mục cha"; img2.Alt = "Xóa danh mục cha"; img3.Alt = "Thêm danh mục con"; img1.Attributes.Add("onclick", "Edit(" + dr["NhomSanPhamID"] + ");"); img2.Attributes.Add("onclick", "Delete(" + dr["NhomSanPhamID"] + ");"); img3.Attributes.Add("onclick", "AddSub(" + dr["NhomSanPhamID"] + ",'" + dr["TenNhomSanPham"] + "');"); tbc3.Controls.Add(img1); tbc4.Controls.Add(img2); tbc5.Controls.Add(img3); tbr.Cells.Add(tbc1); tbr.Cells.Add(tbc2); tbr.Cells.Add(tbc3); tbr.Cells.Add(tbc4); tbr.Cells.Add(tbc5); ds.Tables[0].DefaultView.RowFilter = "NhomChaID=" + dr["NhomSanPhamID"]; DataView dv = ds.Tables[0].DefaultView; if (dv.Count > 0) { img2.Disabled = true; } tblDanhMuc.Rows.Add(tbr); for (int i = 0; i < dv.Count; i++) { HtmlTableRow tvr = new HtmlTableRow(); HtmlTableCell tvc1 = new HtmlTableCell(); HtmlTableCell tvc2 = new HtmlTableCell(); HtmlTableCell tvc3 = new HtmlTableCell(); HtmlTableCell tvc4 = new HtmlTableCell(); HtmlTableCell tvc5 = new HtmlTableCell(); //HtmlTableCell tvc6 = new HtmlTableCell(); HtmlImage imgv1 = new HtmlImage(); HtmlImage imgv2 = new HtmlImage(); tvc4.Style.Add("padding", "0"); tvc4.Style.Add("margin", "0"); tvc5.Style.Add("padding", "0"); tvc5.Style.Add("margin", "0"); tvc4.Style.Add("cursor", "hand"); tvc5.Style.Add("cursor", "hand"); //HtmlImage img3 = new HtmlImage(); imgv1.Src = "../images/Edit.gif"; imgv2.Src = "../images/Delete.gif"; imgv1.Attributes.Add("onclick", "EditSub(" + dr["NhomSanPhamID"] + ",'" + dr["TenNhomSanPham"] + "'," + dv[i]["NhomSanPhamID"] + ");"); imgv2.Attributes.Add("onclick", "Delete(" + dv[i]["NhomSanPhamID"] + ");"); //img3.Src = "../images/AddSub.gif"; imgv1.Alt = "Sửa danh mục con"; imgv2.Alt = "Xóa danh mục con"; tvc4.Controls.Add(imgv1); tvc5.Controls.Add(imgv2); //tbc5.Controls.Add(img3); tvr.Cells.Add(tvc1); tvr.Cells.Add(tvc2); tvr.Cells.Add(tvc3); tvr.Cells.Add(tvc4); tvr.Cells.Add(tvc5); //tvr.Cells.Add(tvc6); tvc3.InnerText = dv[i]["SapXep"] + "." + dv[i]["TenNhomSanPham"]; tblDanhMuc.Rows.Add(tvr); } } } } //tblDanhMuc.Controls.Add(tbl); } catch (Exception ex) { Response.Write(ex.ToString()); } }