close

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Text;

public partial class Default6 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString);
SqlDataAdapter da1, da2;
DataSet ds = new DataSet();
try
{
da1 = new SqlDataAdapter("select id,test_time,title from test", conn);
da2 = new SqlDataAdapter("select id,test_id,article from test_talk", conn);
da1.Fill(ds, "test");
da2.Fill(ds, "test_talk");
ds.Relations.Add("relation_tt",ds.Tables["test"].Columns["id"],ds.Tables["test_talk"].Columns["test_id"]);

foreach (DataRow row1 in ds.Tables["test"].Rows)
{
Panel p1 = new Panel();
Label l1 = new Label();
l1.Text=row1["id"].ToString() + row1["title"].ToString();
p1.Controls.Add(l1);
Page.Form.Controls.Add(p1);

DataTable dt =ds.Tables["test_talk"].Clone();
foreach (DataRow row2 in row1.GetChildRows(ds.Relations["relation_tt"]))
{
dt.ImportRow(row2);
}
Panel p2 = new Panel();
GridView gv = new GridView();
gv.DataSource = dt;
gv.DataBind();
p2.Controls.Add(gv);
Page.Form.Controls.Add(p2);
}
da1.Dispose();
da2.Dispose();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
throw;
}
}
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 ylw1125 的頭像
    ylw1125

    程式搜集分享精靈

    ylw1125 發表在 痞客邦 留言(0) 人氣()