在嵌套的datalist中 需要用<%# DataBinder.Eval(Container.DataItem,["name"]") %> 的绑定方式
不可以用eval("name") 的方式
aspx:三个DataList两次嵌套
<asp:DataList ID="DataList1" runat="server" CellPadding="0">
<ItemTemplate>
<asp:Button ID="Button1" runat="server" BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" OnClick="Button1_Click" Text=' <%# Eval("lmmc") %>' Width="180px" />
<asp:Button ID="Button11" runat="server" Text=' <%# Eval("lmbh") %>' Visible="False" />
<asp:Button ID="Button12" runat="server" Text=' <%# Eval("ljlj") %>' Visible="False" />
<asp:DataList ID="DataList2" runat="server" DataSource=' <%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>'> <ItemTemplate>
<asp:Button ID="Button2" runat="server" BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" OnClick="Button1_Click" Style="margin-left: 15px" Text=' <%# DataBinder.Eval(Container.DataItem,"[\"lmmc\"]") %>' Width="180px" />
<asp:Button ID="Button11" runat="server" Text=' <%# DataBinder.Eval(Container.DataItem,"[\"lmbh\"]") %>' Visible="False"/>
<asp:Button ID="Button12" runat="server" Text=' <%# DataBinder.Eval(Container.DataItem,"[\"ljlj\"]") %>' Visible="False"/>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
protected void bind()
{
SqlConnection con = new SqlConnection(constring);
SqlDataAdapter da = new SqlDataAdapter("select lmmc,lmbh,flid,ljlj FROM DM_LM WHERE flid = 0 and gscs=0 order by pxid", con);
SqlDataAdapter da1 = new SqlDataAdapter("select lmmc,lmbh,flid,ljlj FROM DM_LM WHERE flid > 0 and gscs=1 order by pxid", con);
SqlDataAdapter da2 = new SqlDataAdapter("select lmmc,lmbh,flid,ljlj FROM DM_LM WHERE flid > 0 and gscs=2 order by pxid", con);
DataSet ds = new DataSet();
da.Fill(ds, "LanMuName");
//Response.Write(" <script>alert('aaaa') </script>");
da1.Fill(ds, "LanMuName1");
//Relations:将父表LanMuName与子表LanMuName1相连接,
ds.Relations.Add("myrelation", ds.Tables[0].Columns[1], ds.Tables[1].Columns[2], false);
da2.Fill(ds, "LanMuName2");
//Relations:将父表LanMuName1与子表LanMuName2相连接,
ds.Relations.Add("myrelation2", ds.Tables[1].Columns[1], ds.Tables[2].Columns[2], false);
DataList1.DataSource = ds.Tables[0];
DataList1.DataBind();
con.Close();
}
不可以用eval("name") 的方式
aspx:三个DataList两次嵌套
<asp:DataList ID="DataList1" runat="server" CellPadding="0">
<ItemTemplate>
<asp:Button ID="Button1" runat="server" BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" OnClick="Button1_Click" Text=' <%# Eval("lmmc") %>' Width="180px" />
<asp:Button ID="Button11" runat="server" Text=' <%# Eval("lmbh") %>' Visible="False" />
<asp:Button ID="Button12" runat="server" Text=' <%# Eval("ljlj") %>' Visible="False" />
<asp:DataList ID="DataList2" runat="server" DataSource=' <%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>'> <ItemTemplate>
<asp:Button ID="Button2" runat="server" BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" OnClick="Button1_Click" Style="margin-left: 15px" Text=' <%# DataBinder.Eval(Container.DataItem,"[\"lmmc\"]") %>' Width="180px" />
<asp:Button ID="Button11" runat="server" Text=' <%# DataBinder.Eval(Container.DataItem,"[\"lmbh\"]") %>' Visible="False"/>
<asp:Button ID="Button12" runat="server" Text=' <%# DataBinder.Eval(Container.DataItem,"[\"ljlj\"]") %>' Visible="False"/>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
protected void bind()
{
SqlConnection con = new SqlConnection(constring);
SqlDataAdapter da = new SqlDataAdapter("select lmmc,lmbh,flid,ljlj FROM DM_LM WHERE flid = 0 and gscs=0 order by pxid", con);
SqlDataAdapter da1 = new SqlDataAdapter("select lmmc,lmbh,flid,ljlj FROM DM_LM WHERE flid > 0 and gscs=1 order by pxid", con);
SqlDataAdapter da2 = new SqlDataAdapter("select lmmc,lmbh,flid,ljlj FROM DM_LM WHERE flid > 0 and gscs=2 order by pxid", con);
DataSet ds = new DataSet();
da.Fill(ds, "LanMuName");
//Response.Write(" <script>alert('aaaa') </script>");
da1.Fill(ds, "LanMuName1");
//Relations:将父表LanMuName与子表LanMuName1相连接,
ds.Relations.Add("myrelation", ds.Tables[0].Columns[1], ds.Tables[1].Columns[2], false);
da2.Fill(ds, "LanMuName2");
//Relations:将父表LanMuName1与子表LanMuName2相连接,
ds.Relations.Add("myrelation2", ds.Tables[1].Columns[1], ds.Tables[2].Columns[2], false);
DataList1.DataSource = ds.Tables[0];
DataList1.DataBind();
con.Close();
}