首页 > 代码库 > Repeater嵌套gridview,主从表展示

Repeater嵌套gridview,主从表展示

点击详细:展示详细内嵌套的gridview信息。

显示效果:

局点:0到货时间:2014-11-020接收人:签0详细
  
局点:1到货时间:2014-11-021接收人:签1详细
 
时间状态接收人
2014-11-020签0
局点:2到货时间:2014-11-022接收人:签2详细
  
局点:3到货时间:2014-11-023接收人:签3详细

 

<asp:UpdatePanel ID="UpdatePanel1" runat="server">            <ContentTemplate>                <asp:Repeater ID="Repeater1" runat="server">                    <HeaderTemplate>                        <table>                    </HeaderTemplate>                    <ItemTemplate>                        <tr>                            <td>                                局点:<%# Eval("JdName")%>                            </td>                            <td>                                到货时间:<%# Eval("JdTime")%>                            </td>                            <td>                                接收人:<%# Eval("JdJsr")%>                            </td>                            <td>                                <asp:LinkButton ID="LinkButton1" OnCommand="bindDetail" CommandArgument='<%# Eval("JdName")%>'                                    runat="server">详细</asp:LinkButton>                            </td>                        </tr>                        <tr>                        <td colspan="1"></td>                            <td colspan="3">                                <asp:GridView ID="GridView1" Width="100%" Visible="false" AutoGenerateColumns="false" runat="server">                                    <Columns>                                        <asp:BoundField HeaderText="时间状态" DataField="JdTime" />                                        <asp:BoundField HeaderText="接收人" DataField="JdJsr" />                                    </Columns>                                </asp:GridView>                                                           </td>                        </tr>                    </ItemTemplate>                    <FooterTemplate>                        </table>                    </FooterTemplate>                </asp:Repeater>            </ContentTemplate>        </asp:UpdatePanel>


 

  protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            bindJuDian();        }    }    protected void bindDetail(object sender, EventArgs e)    {        List<JuDianEnty> Data1 = new List<JuDianEnty>();        string sid = ((LinkButton)sender).CommandArgument;        int ss = Convert.ToInt32(sid);        for (int i = 0; i < ss; i++)        {            JuDianEnty model = new JuDianEnty();            model.JdName = "DT" + i;            model.JdTime = System.DateTime.Now.ToString("yyyy-MM-dd") + i;            model.JdJsr = "签" + i;            Data1.Add(model);        }        int lindex = ((RepeaterItem)((LinkButton)sender).NamingContainer).ItemIndex;        foreach (RepeaterItem item in Repeater1.Items)        {            GridView gv1 = item.FindControl("GridView1") as GridView;            if (item.ItemIndex == lindex)            {                gv1.DataSource = Data1;                gv1.DataBind();                gv1.Visible = true;            }            else            {                gv1.Visible = false;            }        }    }    protected void bindJuDian()    {        List<JuDianEnty> Data1 = new List<JuDianEnty>();          for (int i = 0; i < 4; i++)        {            JuDianEnty model = new JuDianEnty();            model.JdName =  i.ToString();            model.JdTime = System.DateTime.Now.ToString("yyyy-MM-dd") + i;            model.JdJsr = "签" + i;            Data1.Add(model);        }        Repeater1.DataSource = Data1;        Repeater1.DataBind();    }}public class JuDianEnty{    public JuDianEnty()        { }      private string _jdname;        private string _jdtime;        private string _jdjsr;        public string JdName        {            set { _jdname = value; }            get { return _jdname; }        }        public string JdTime        {            set { _jdtime = value; }            get { return _jdtime; }        }        public string JdJsr        {            set { _jdjsr = value; }            get { return _jdjsr; }        }}


 

Repeater嵌套gridview,主从表展示