码迷,mamicode.com
首页 > 其他好文 > 详细

Repeater嵌套gridview

时间:2014-06-27 18:27:12      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:tar   ext   get   数据   string   os   

前台:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="Repeater1_ItemDataBound">
        <ItemTemplate>
           id:<%#Eval("ID")%>
           carid:<%#Eval("car_id")%>
           <asp:GridView ID="inGridView" runat="server" AutoGenerateColumns="False">
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                    SortExpression="ID" />
                <asp:BoundField DataField="name1" HeaderText="name1" SortExpression="name1" />
                <asp:BoundField DataField="sex" HeaderText="sex" SortExpression="sex" />
                <asp:BoundField DataField="qu" HeaderText="qu" SortExpression="qu" />
            </Columns>
        </asp:GridView>
           userid:<%#Eval("userID")%>
        </ItemTemplate>
        </asp:Repeater>

后台:
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            GridView gridview = (GridView)e.Item.FindControl("inGridView");
            DataRowView rowv = (DataRowView)e.Item.DataItem;
            string id = Convert.ToString(rowv["car_id"]);//Repeater1中绑定中的数据,也即主表上和子表的关联字段
            if (id != null && id != "")
            {
                string sqltext = "select top 5 id,name1,sex,qu from second where id=‘" + id + "‘";
                DataSet ds = datacontrol.getdatas(sqltext);//获取从数据,这里是我的数据提取类,换成你自己的数据提取方法
                if (ds != null)
                {
                    try
                    {
                        gridview.DataSource = ds;
                        gridview.DataBind();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }

        }

Repeater嵌套gridview,布布扣,bubuko.com

Repeater嵌套gridview

标签:tar   ext   get   数据   string   os   

原文地址:http://www.cnblogs.com/lxboy2009/p/3809807.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!