객체를 이용해 Repeater 안에 Repeater 넣기 ¶
준비중
중첩된 Repeater 안에서 상위 Repeater 접근하기 ¶
<%# DataBinder.Eval(((System.Web.UI.WebControls.ListViewDataItem)Container.Parent.Parent.Parent).DataItem,"idx") %>
DataSet을 이용해 Repeater 안에 Repeater 넣기 ¶
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["mpConnectionString"].ConnectionString))
{
string query =
@" SELECT COUNT(M.idx)
FROM mp_Product_Make AS M INNER JOIN
mp_Product AS P ON M.product_idx = P.idx INNER JOIN
mp_ProductImages AS I ON M.image_idx = I.idx
WHERE (M.idx > 0) " + searchTemp;
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = query;
conn.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
tCnt = reader.GetInt32(0);
}
}
query = @"SELECT * FROM(
SELECT M.idx, P.product_Price + I.image_Price as Price, I.image_Title, M.cmd_count, M.product_Color, P.product_Color AS product_Colors, ROW_NUMBER() OVER(ORDER BY M.idx DESC) AS ROW
FROM mp_Product_Make AS M INNER JOIN
mp_Product AS P ON M.product_idx = P.idx INNER JOIN
mp_ProductImages AS I ON M.image_idx = I.idx
WHERE (M.idx > 0) " + searchTemp + @"
)AS PRODUCTS WHERE ROW BETWEEN @startRow AND @endRow";
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = query;
cmd.Parameters.Add("@startRow", SqlDbType.Int).Value = 0;
cmd.Parameters.Add("@endRow", SqlDbType.Int).Value = 12;
DataSet ds = new DataSet();
using (SqlDataAdapter adpt = new SqlDataAdapter(cmd))
{
adpt.Fill(ds, "products");
}
List<ProductColor> colors = new ProductColorManager().getProductColors();
DataTable dt = new DataTable("productColors");
dt.Columns.Add("idx",Type.GetType("System.Int32"));
dt.Columns.Add("color_idx");
dt.Columns.Add("color_Code");
dt.Columns.Add("color_Name");
foreach (DataRow dr in ds.Tables["products"].Rows)
{
string productColor = dr["product_colors"].ToString();
foreach (ProductColor c in colors)
{
if (productColor.IndexOf("|" + c.idx + "|") != -1)
{
dt.Rows.Add(dr["idx"], c.idx, c.colorCode, c.colorName);
}
}
}
ds.Tables.Add(dt);
ds.Relations.Add("colorRelation",
ds.Tables["products"].Columns["idx"],
ds.Tables["productColors"].Columns["idx"]);
articleListView.DataSource = ds.Tables["products"];
articleListView.DataBind();
}
<asp:ListView ID="articleListView" runat="server" GroupItemCount="4">
<LayoutTemplate>
<asp:PlaceHolder ID="groupPlaceHolder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<GroupTemplate>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
</GroupTemplate>
<GroupSeparatorTemplate>
<hr />
</GroupSeparatorTemplate>
<ItemTemplate>
<div class="article">
<div class="thumbnail">
<a href="javascript:ViewPage('<%#Eval("idx")%>','view_form');"><img src="<%#UploadedImageManager.getImageURL((int)Eval("idx"),"mp_Product_Make",false,"front")%>" /></a>
</div>
<div class="summary">
<a href="javascript:ViewPage('<%#Eval("idx")%>','view_form');"><%#Eval("image_Title")%></a><br />
가격 : <%#Eval("Price")%> , 덧글 : <%#Eval("cmd_count")%>
<asp:PlaceHolder runat="server" Visible='<%#string.IsNullOrEmpty(Eval("product_Color").ToString()) ? true : false %>'>
<!-- 색상 선택 시작 -->
<br /><span style="color:Red;">색상 미지정됨</span>
<br />
<asp:repeater id="colorRepeater" runat="server" datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("colorRelation") %>'>
<ItemTemplate>
<div style="background-color:#<%# DataBinder.Eval(Container.DataItem, "[\"color_Code\"]")%>;" class="colorBox"><img onclick="location.href='board_change_color.aspx?idx=<%# DataBinder.Eval(Container.DataItem, "[\"idx\"]")%>&color_idx=<%# DataBinder.Eval(Container.DataItem, "[\"color_idx\"]")%>&curPage=<%=req_curPage %>'" src="/mp/images/machine/img_color.gif" /></div>
</ItemTemplate>
</asp:Repeater>
<!-- 색상 선택 끝 -->
</asp:PlaceHolder>
</div>
</div>
</ItemTemplate>
<EmptyDataTemplate>
<p>등록된 상품이 없습니다.</p>
</EmptyDataTemplate>
</asp:ListView>