标签:style blog color io ar div log new
主要是设置主从表关系
前台
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="费用id" > <ItemTemplate> <asp:Label ID="lbl01" runat="server" Text=‘<%#Eval("rentid") %>‘></asp:Label> <asp:GridView ID="GridView2" runat="server" DataSource=‘<%#((System.Data.DataRowView)Container.DataItem).CreateChildView("tableRelation") %>‘ DataMember="rentid"> </asp:GridView> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
后台:
string sql = "select rentid from lesseeRent select * from lesseeRentDetails"; System.Data.DataSet ds = SQLServerHelper.GetDataSet(System.Data.CommandType.Text, sql); ds.Tables[0].TableName = "rent"; ds.Tables[1].TableName = "rentDetails"; DataColumn parent = ds.Tables["rent"].Columns["rentid"]; DataColumn child=ds.Tables["rentDetails"].Columns["rentid"]; DataRelation dtRelation = new DataRelation("tableRelation", parent, child, false); ds.Relations.Add( dtRelation); GridView1.DataSource = ds; GridView1.DataBind();
标签:style blog color io ar div log new
原文地址:http://www.cnblogs.com/zhaolijing910/p/3910304.html