Monday, January 28, 2008

DataList嵌套DataGrid

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
this.DL_DataClass.Attributes.Add("style","word-break:keep-all;word-wrap:normal");
//Class1
string[] strSqlArray =new string[2]{"select IOrder, ILevel, IParentID, NavigatorID, NodeCaption from NavigatorNodes where ILevel = 1"," Order By IOrder" };
string strSql=string.Concat(strSqlArray);
this.dbClass.AdapterFill(ds,CommandType.Text,strSql,"Class1",new OleDbParameter[0]);

string[] strSqlArray1 =new string[1]{"select IOrder, ILevel, IParentID, NavigatorID, NodeCaption from NavigatorNodes where IParentID in (select NavigatorID from NavigatorNodes where ILevel = 1)"};
string strSql1=string.Concat(strSqlArray1);
this.dbClass.AdapterFill(ds,CommandType.Text,strSql1,"ClassList",new OleDbParameter[0]);

ds.Relations.Add("MyRelation",ds.Tables["Class1"].Columns["NavigatorID"],ds.Tables["ClassList"].Columns["IParentID"]);

this.DL_Class1.DataSource =ds.Tables["Class1"].DefaultView;
this.DL_Class1.DataBind();

ds.Dispose();
}
}

[asp:datalist id="DL_Class1" runat="server" BorderColor="Black" ShowFooter="False" ShowHeader="False"
RepeatDirection="Horizontal" RepeatColumns="2" BorderWidth="0px" CellPadding="2" BackColor="White"
CellSpacing="15" GridLines="Vertical" CaptionAlign="Bottom">
[SeparatorStyle BorderWidth="1px" BorderStyle="Solid" BorderColor="Silver" BackColor="Transparent">
[ItemStyle ForeColor="White" Width="300px" VerticalAlign="Top" BackColor="WhiteSmoke">
[ItemTemplate>
[div style="BACKGROUND-COLOR: background" style="BORDER-BOTTOM: #003366 1px solid; Height:20px; vAlign:middle">[b>[%# DataBinder.Eval(Container.DataItem,"NavigatorID") %> [%# DataBinder.Eval(Container.DataItem,"NodeCaption") %>
[/div>
[asp:DataGrid ID=dg1 Width=300px Runat=server DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("MyRelation") %>' AutoGenerateColumns="false" ShowHeader="false" ShowFooter="false" PageSize="4" AllowPaging="true" PagerStyle-Visible="false" BorderWidth="0" CellPadding="0" CellSpacing="1" GridLines="Vertical">
[ItemStyle Height="15px">
[AlternatingItemStyle BackColor="#ddeedd" Height="15px">[/AlternatingItemStyle>
[Columns>
[asp:TemplateColumn>
[ItemTemplate>
[%# DataBinder.Eval(Container.DataItem,"[\"IParentID\"]") %>
@[%# DataBinder.Eval(Container.DataItem,"[\"NodeCaption\"]") %>
[/ItemTemplate>
[/asp:TemplateColumn>
[/Columns>
[/asp:DataGrid>
[div align="right">[a href="javascript:;">[i>More[/i>[/div>
[/ItemTemplate>
[/asp:datalist>


Related Posts



0 Comments:

 

gf

rgdfgfdg

gf

gf

gf