|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
前几天同学问我学习方向的问题。有点想法,不知道对不对,怕误导同学,现在“开源一下”。注:括号内是我现在整理的时填加上的。控件|数据|显现(一).显现最终效果
(二)代码
1.前台界面代码:
<%@Pagelanguage="c#"Codebehind="WebForm1.aspx.cs"AutoEventWireup="false"Inherits="数据绑定控件同时显现主表和子表数据.WebForm1"%>
<%@ImportNamespace="System.Data"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<metaname="GENERATOR"Content="MicrosoftVisualStudio.NET7.1">
<metaname="CODE_LANGUAGE"Content="C#">
<metaname="vs_defaultClientScript"content="JavaScript">
<metaname="vs_targetSchema"content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<bodyMS_POSITIONING="GridLayout">
<formid="Form1"method="post"runat="server">
<!--绑定主表数据-->
<asp:repeaterid="myRepeater"runat="server">
<HeaderTemplate>
<tableborder="0"bgcolor="lightblue">
</HeaderTemplate>
<ItemTemplate>
<tr>
<tdstyle="background-color:lightgray">
<b>
<%#DataBinder.Eval(Container.DataItem,"TypeID")%>
<%#DataBinder.Eval(Container.DataItem,"TypeName")%>
</b>
<br>
<!--绑定子表数据-->
<asp:repeaterid="childRepeater"datasource=<%#((DataRowView)Container.DataItem)
.Row.GetChildRows("TypeRelation")%>runat="server">
<itemtemplate>
<tableborder="0"bgcolor="#ffcc33">
<tr>
<td>
<%#DataBinder.Eval(Container.DataItem,"["TypeID"]")%>
<%#DataBinder.Eval(Container.DataItem,"["TypeDetail"]")%>
<br>
</td>
</tr>
</table>
</itemtemplate>
</asp:repeater>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:repeater>
</form>
</body>
</HTML>
2.儿女代码
usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Web;
usingSystem.Web.SessionState;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.HtmlControls;
namespace数据绑定控件同时显现主表和子表数据
{
///<summary>
///数据绑定控件同时显现主表和子表数据
///</summary>
publicclassWebForm1:System.Web.UI.Page
{
protectedSystem.Web.UI.WebControls.RepeatermyRepeater;
privatevoidPage_Load(objectsender,System.EventArgse)
{
DataSetds=newDataSet();
//1.机关主表
DataTabledtTypeParent=newDataTable();
dtTypeParent.Columns.Add(newDataColumn("TypeID",typeof(int)));
dtTypeParent.Columns.Add(newDataColumn("TypeName",typeof(string)));
//给主表增加两笔记录
DataRowdrParent1=dtTypeParent.NewRow();
drParent1["TypeID"]=1;
drParent1["TypeName"]="生果";
dtTypeParent.Rows.Add(drParent1);
DataRowdrParent2=dtTypeParent.NewRow();
drParent2["TypeID"]=2;
drParent2["TypeName"]="玩具";
dtTypeParent.Rows.Add(drParent2);
dtTypeParent.TableName="TypeParent";
dtTypeParent.PrimaryKey=newDataColumn[]{dtTypeParent.Columns["TypeID"]};
ds.Tables.Add(dtTypeParent);
//2.机关子表
DataTabledtTypeChild=newDataTable();
dtTypeChild.Columns.Add(newDataColumn("TypeID",typeof(int)));
dtTypeChild.Columns.Add(newDataColumn("TypeDetail",typeof(string)));
//给子表增加五笔记录
DataRowdrChild1=dtTypeChild.NewRow();
drChild1["TypeID"]=1;
drChild1["TypeDetail"]="苹果";
dtTypeChild.Rows.Add(drChild1);
DataRowdrChild2=dtTypeChild.NewRow();
drChild2["TypeID"]=1;
drChild2["TypeDetail"]="桔子";
dtTypeChild.Rows.Add(drChild2);
DataRowdrChild3=dtTypeChild.NewRow();
drChild3["TypeID"]=1;
drChild3["TypeDetail"]="喷鼻蕉";
dtTypeChild.Rows.Add(drChild3);
DataRowdrChild4=dtTypeChild.NewRow();
drChild4["TypeID"]=2;
drChild4["TypeDetail"]="呆板人";
dtTypeChild.Rows.Add(drChild4);
DataRowdrChild5=dtTypeChild.NewRow();
drChild5["TypeID"]=2;
drChild5["TypeDetail"]="小汽车";
dtTypeChild.Rows.Add(drChild5);
dtTypeChild.TableName="TypeChild";
ds.Tables.Add(dtTypeChild);
ds.Relations.Add("TypeRelation",
ds.Tables["TypeParent"].Columns["TypeID"],
ds.Tables["TypeChild"].Columns["TypeID"]);
myRepeater.DataSource=ds.Tables["TypeParent"];
Page.DataBind();
}
#regionWeb窗体计划器天生的代码
overrideprotectedvoidOnInit(EventArgse)
{
//
//CODEGEN:该挪用是ASP.NETWeb窗体计划器所必须的。
//
InitializeComponent();
base.OnInit(e);
}
///<summary>
///计划器撑持所需的办法-不要利用代码编纂器修正
///此办法的内容。
///</summary>
privatevoidInitializeComponent()
{
this.Load+=newSystem.EventHandler(this.Page_Load);
}
#endregion
}
}
我之所以想学。NET,是因为一直觉的BILLGATES好厉害,希望有一天能去微软,虽然现在还距离遥远,呵呵:) |
|