repeater 嵌套内层repeater 动态获取外层 repeater 值的问题

时间:2021-12-06 03:14:45
<asp:Repeater runat="server" ID="rptypelist" OnItemDataBound="rptypelist_ItemDataBound"> 

                <ItemTemplate>
                    <dt>
                        <label id='<%#Container.DataItem %>'>
                            <%#Container.DataItem %></label><div>
                                <span>&nbsp;</span></div><a href="#pageTop" class="gotop">返回顶部↑</a>
                    </dt>
                    <dd>
                        <ul>                            
                            <asp:Repeater runat="server" ID="hotcarlist">
                                <ItemTemplate>
                                    <li>
                                        <div class="name">
                                            <a href='/buycar/serial/<%#BitAuto.Ucar.Utils.Caching.CarCache.GetAllSpellByCsId(Eval("Cs_Id"))%>/' target="_blank"><%#Eval("Cs_Name").ToString()%></a><a href='/buycar/cc/<%#Eval("Cs_Id") %>/'
                                                class="classify" target="_blank">[ <%#BitAuto.Ucar.Utils.Caching.CarCache.GetCsCarLevelByCsId(Eval("Cs_Id"))%>]</a></div>
                                        <div class="bj">
                                            <%#Eval("MinPrice","{0:F1}") %>万-<%#Eval("MaxPrice", "{0:F1}")%>万</div>
                                    </li>
                                </ItemTemplate>
                            </asp:Repeater>
                        </ul>
                    </dd>
                </ItemTemplate>
            </asp:Repeater>
 

 private void RpTypeBind()
        {
            string[] AZ = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
            rptypelist.DataSource = AZ;
            this.rptypelist.DataBind();
        }
        protected void rptypelist_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {

            //判断里层repeater处于外层repeater的哪个位置( AlternatingItemTemplate,FooterTemplate,
            //HeaderTemplate,,ItemTemplate,SeparatorTemplate)
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rep = e.Item.FindControl("hotcarlist") as Repeater;//找到里层的repeater对象
                string rowv = (string)e.Item.DataItem;//找到分类Repeater关联的数据项 
                DataTable dtCarSource = CarSerialBLL.GetHotSerialCarAmount();
                dtCarSource.Columns.Add("FirstChar", System.Type.GetType("System.String"));//添加车系名首字母列
                foreach (DataRow row in dtCarSource.Rows)
                {
                    string CsName = row["Cs_Name"].ParseToString();
                    row["FirstChar"] = StringHelper.GetFirstCharPY(CsName);
                }
                string strID = "A";
                DataRow[] dtRow = dtCarSource.Select("FirstChar='" + strID + "'");
                DataTable dtable = dtCarSource.Clone();
                foreach (DataRow r in dtRow)
                {
                    dtable.ImportRow(r);
                }
                rep.DataSource = dtable;
                rep.DataBind();
            }
        }

我想动态获取ABCD的值,现在是写死的“A”我的需求是外层是26个大写字母,内层是以这些字母开头的车名比如:A下有奥迪,奥拓,B下有比亚迪

3 个解决方案

#1


你把ABCD 等等字母当作一个类       以字母开头的车名当作 每个类下面的产品   处理 不就行了么?

#2


引用 1 楼 liukaizxc 的回复:
你把ABCD 等等字母当作一个类 以字母开头的车名当作 每个类下面的产品 处理 不就行了么?

经您指点,顿悟了,谢谢啦!

#3


这里有例子
嵌套的数据控件在子控件绑定时访问父控件的数据绑定项的方法
http://dotnet.aspx.cc/file/Access-Parent-DataItem-When-DataBinding-in-Nested-Data-Controls.aspx

http://dotnet.aspx.cc/article/54f4c732-aae2-4135-fb1b-7b4b613baa33/read.aspx

#1


你把ABCD 等等字母当作一个类       以字母开头的车名当作 每个类下面的产品   处理 不就行了么?

#2


引用 1 楼 liukaizxc 的回复:
你把ABCD 等等字母当作一个类 以字母开头的车名当作 每个类下面的产品 处理 不就行了么?

经您指点,顿悟了,谢谢啦!

#3


这里有例子
嵌套的数据控件在子控件绑定时访问父控件的数据绑定项的方法
http://dotnet.aspx.cc/file/Access-Parent-DataItem-When-DataBinding-in-Nested-Data-Controls.aspx

http://dotnet.aspx.cc/article/54f4c732-aae2-4135-fb1b-7b4b613baa33/read.aspx