62,041
社区成员
发帖
与我相关
我的任务
分享
<asp:DataList ID="Dlt_Class" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" BorderColor="White" EnableTheming="True" Height="422px" Width="736px">
<ItemTemplate>
<table style="width: 242px; border-right: lime 3px double; border-top: lime 3px double; border-left: lime 3px double; border-bottom: lime 3px double;">
<tr>
<td style="width: 223px; font-weight: bold; font-size: 10pt;" align="center">
<a href="ClassType.aspx?id=<%# Eval("PKID") %>&twoid=<%# Eval("UPID") %>"><%# DataBinder.Eval(Container.DataItem, "ClassName")%></a>
</td>
</tr>
<tr>
<td style="width: 223px; height: 73px;">
<asp:DataList id="childDataList" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>'> /////下面的无法绑定
<HeaderTemplate>
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>
</HeaderTemplate>
<itemtemplate>
<a href="ClassType.aspx?id=<%# Eval("[\"PKID\"]") %>&twoid=<%# Eval("[\"UPID\"]") %>"><%# DataBinder.Eval(Container.DataItem, "[\"ClassName\"]")%></a>
</itemtemplate>
<FooterTemplate>
</td>
</tr>
</table>
</FooterTemplate>
</asp:DataList></td>
</tr>
</table>
</ItemTemplate>
<ItemStyle VerticalAlign="Top" />
</asp:DataList>
public void Bind()
{
string strSQL,strSQL1, strSQL2;
strSQL1 = "select * from t_sj_ClassInfo where UPID=0 ";
strSQL2 = "select * from t_sj_ClassInfo where UPID<>0 ";
strSQL = strSQL1 + ";" + strSQL2;
DataSet ds = GetDataSet(strSQL);
ds.Relations.Add("myrelation", ds.Tables[0].Columns["PKID"], ds.Tables[1].Columns["PKID"],false);
Dlt_Class.DataSource = ds.Tables[0];
Dlt_Class.DataBind();
}
public static DataSet GetDataSet(string sql)
{
SqlDataAdapter da = null;
DataSet ds = new DataSet();
int i = 1;
string[] strSqls = sql.Split(';');
foreach (string strSql in strSqls)
{
da = GetAdapter(strSql);
da.Fill(ds, "table" + i.ToString());
i++;
}
return ds;
}
public static SqlDataAdapter GetAdapter(string sql)
{
SqlDataAdapter da = new SqlDataAdapter((SqlCommand)GetCommand(sql));
return da;
}
public static IDbCommand GetCommand(string sql)
{
IDbCommand cmd = new SqlCommand(sql, (SqlConnection)GetConnection());
return cmd;
}
public static IDbConnection GetConnection()
{
IDbConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["dbConnStr"]);
return cnn;
}
public void Bind()
{
string strSQL,strSQL1, strSQL2;
strSQL1 = "select * from t_sj_ClassInfo where UPID=0 ";
strSQL2 = "select * from t_sj_ClassInfo where UPID<>0 ";
strSQL = strSQL1 + ";" + strSQL2;
DataSet ds = GetDataSet(strSQL);
Dlt_Class.DataSource = ds.Tables[0];
Dlt_Class.DataBind();
childDataList.DataSource=ds.Tables[1];
childDataList.DataBind();
}
public static DataSet GetDataSet(string sql)
{
DataSet ds = new DataSet();
SqlDataAdapter da = GetAdapter(strSql);
da.Fill(ds);
return ds;
}