眼看就要到上班的日子了,希望大家抓住宝贵时间能吃则吃,能乐则乐repeater简单应用(嵌套绑定)
咱还是节省网络资源,进入正题。。

说起repeater嵌套,好像从N久就有了,这个例子是前些日子做的,用了三层嵌套实现有,先说下,因为客观需求,并没有考虑到性能上的问题,所以可以看下其中的方法,至于别的可以自己探索下,呵呵。

功能是要实现一个下拉列表,列表顶层是可以动态设置的年份时间段,第二层则是时间段内具体的年份列表,最内层是每年的信息列表,因为时间问题,就直接用三个repeater来实现了此功能了,从外层向内层根据条件进行逐层绑定,具体的实现如下

先看下HTML:

 1repeater简单应用(嵌套绑定)<asp:Repeater ID="Repeater1" runat="server">
 2repeater简单应用(嵌套绑定)                                                <ItemTemplate>
 3repeater简单应用(嵌套绑定)                                                    <div>
 4repeater简单应用(嵌套绑定)                                                        <span>
 5repeater简单应用(嵌套绑定)                                                            <asp:Literal ID="lblid" runat="server" Text='<%# Eval("history_id") %>' Visible="false"></asp:Literal>
 6repeater简单应用(嵌套绑定)                                                            <asp:Literal ID="lblstart" runat="server" Text='<%# Eval("history_start")%>'></asp:Literal>-<asp:Literal
 7repeater简单应用(嵌套绑定)                                                                ID="lblend" runat="server" Text='<%# Eval("history_end")%>'></asp:Literal>
 8repeater简单应用(嵌套绑定)                                                        </span>
 9repeater简单应用(嵌套绑定)                                                        <asp:Repeater ID="Repeater2" runat="server">
10repeater简单应用(嵌套绑定)                                                            <ItemTemplate>
11repeater简单应用(嵌套绑定)                                                                <p style="color: #000000; margin-left: -20px;">
12repeater简单应用(嵌套绑定)                                                                    <asp:Literal ID="lblyear" runat="server" Text='<%# Eval("his_year") %>'></asp:Literal></p>
13repeater简单应用(嵌套绑定)                                                                <asp:Repeater ID="Repeater3" runat="server">
14repeater简单应用(嵌套绑定)                                                                    <ItemTemplate>
15repeater简单应用(嵌套绑定)                                                                        <a href="history.aspx?id=<%# Eval("his_id") %>" style="padding-left: 30px; text-decoration: underline;">
16repeater简单应用(嵌套绑定)                                                                            <%# Eval("his_title")%></a>
17repeater简单应用(嵌套绑定)                                                                    </ItemTemplate>
18repeater简单应用(嵌套绑定)                                                                </asp:Repeater>
19repeater简单应用(嵌套绑定)                                                            </ItemTemplate>
20repeater简单应用(嵌套绑定)                                                        </asp:Repeater>
21repeater简单应用(嵌套绑定)                                                    </div>
22repeater简单应用(嵌套绑定)                                                </ItemTemplate>
23repeater简单应用(嵌套绑定)                                            </asp:Repeater>

(其实repeater和平常的控件一样,所以别让心理打败就好,呵呵)
此段HTML很简单,三个repeater,每一层都有标识字段(为了进行FindControl),此方法好像是地球人都知道#24,剩下的都是基本数据绑定了,至于内部样式不必去管。

再看下CS文件:

1repeater简单应用(嵌套绑定)   private void HisBind()
2    }

这个是最外层的年段列表绑定(简单)。

关键在下面这个方法中:

 1repeater简单应用(嵌套绑定)private void YearBind()
 2        }

可以看到此方法中用了多个循环,所以效率肯定不是很好。。
看下功能,首先把所有年份信息查询出来~~信息量不算大,呵呵
遍历最外层的repeater,也就是时间段,通过findcontrol找出标题起始时间与终止时间,以及要进行绑定的第二层repeater,通过遍历刚查询出来的所有年份信息来判断是否在此时间段内,若是,则存储在临时的IList year中,直至循环结束,第二层的数据也就绑定出来了~~

在上面第二层的信息已经查询出来,repyear(第二层)的信息也就存在了,对它进行遍历,查询出内部标识具体年份的临时变量year,通过his_c_mana.GetList方法把这一年的所有信息查询出来并绑定在最内层repeater中。

好像绑定完了,呵呵

还是那句,这个功能只存在逻辑,并没有考虑到性能问题。

相关文章:

  • 2022-02-24
  • 2021-08-01
  • 2021-12-07
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-07
相关资源
相似解决方案