Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 软件时空 > 软件相关 > DataList中嵌套DataList的例子
【标  题】:DataList中嵌套DataList的例子
【关键字】:DataList,DataList
【来  源】:http://www.cublog.cn/u/674/showart.php?id=145973

DataList中嵌套DataList的例子

Your Ad Here

这个例子是来源于 asp.net start kit

 

<%@ Page language="c#" Codebehind="WebForm4.aspx.cs" AutoEventWireup="false" Inherits="localtest.WebForm4" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<HTML>

     <HEAD>

           <title>WebForm4</title>

           <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">

           <meta name="CODE_LANGUAGE" Content="C#">

           <meta name="vs_defaultClientScript" content="JavaScript">

           <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

     </HEAD>

     <body MS_POSITIONING="GridLayout">

           <form id="Form1" method="post" runat="server">

                <asp:DataList ID="dgTopLevel" Runat="server">

                     <ItemTemplate>

                           <asp:LinkButton Runat="server" id="open" CommandName="打开" >open</asp:LinkButton>

                           <asp:Label Runat="server" ID="lb">这是第一层</asp:Label>

                           <%# DataBinder.Eval(Container.DataItem,"au_lname") %>

                     </ItemTemplate>

                     <SelectedItemTemplate>

                           <asp:LinkButton Runat="server" ID="close" CommandName="关闭" >close</asp:LinkButton>

                           <asp:Label Runat="server" ID="lb2">这是第二层</asp:Label>

                           <asp:DataList Runat="server" ID="dgSub" DataSource="<%# GetSubList() %>">

                           <ItemTemplate>

                           <%# DataBinder.Eval(Container.DataItem,"au_fname") %>

                          

                           </ItemTemplate>

                           </asp:DataList>

                     </SelectedItemTemplate>

                </asp:DataList>

           </form>

     </body>

</HTML>

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

 

namespace localtest

{

     /// <summary>

     /// WebForm4 的摘要说明。

     /// </summary>

     public class WebForm4 : System.Web.UI.Page

     {

           protected System.Web.UI.WebControls.DataList dgTopLevel;         

    

           private void Page_Load(object sender, System.EventArgs e)

           {

                // 在此处放置用户代码以初始化页面

                if(!IsPostBack)

                {

                     BindList();

                }

 

 

 

           }

 

           public void Command_select(Object sender,DataListCommandEventArgs e)

           {

                string command = ((LinkButton)e.CommandSource).CommandName;

 

          

                if(command == "close")

                {

                     dgTopLevel.SelectedIndex = -1;

                }

                else

                {

                     dgTopLevel.SelectedIndex = e.Item.ItemIndex;

                }

                BindList();

           }

 

           #region Web 窗体设计器生成的代码

           #endregion

 

          

 

           void BindList()

           {

                          

                this.dgTopLevel.DataSource = this.GetTopList();

                this.dgTopLevel.DataBind();

           }

 

           //第二层的数据源

           public SqlDataReader GetSubList()

           {

                SqlConnection conn = new SqlConnection("server=localhost;uid=sa;pwd=syd8gmt;database=pubs");

                string strsql = "select top 5 au_fname from authors";

                SqlCommand cmd = new SqlCommand(strsql,conn);

                cmd.Connection.Open();

                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

               

                return dr;

           }

           //第一层的数据源

           public SqlDataReader GetTopList()

           {

 

 

                SqlConnection conn = new SqlConnection("server=localhost;uid=sa;pwd=syd8gmt;database=pubs");

                string strsql = " select top 10 au_lname from authors";

           

                SqlCommand cmd = new SqlCommand(strsql,conn);

                cmd.Connection.Open();

                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

 

                return dr;

           }

 

            

     }

}

vc技巧集锦:【上一篇】
向shell初学者介绍一些学习经验:【下一篇】
【相关文章】
  • 再來一個DataList的ItemTemplate的例子
  • ASP.NET中DataGrid和DataList控件用法比较
  • 关于在DataList中加入删除确认
  • 用DataList + Repeater实现二级下拉列表 当前被点击的字体加粗.
  • DataList嵌套DataList的实现
  • Understanding the Differences Among the DataGrid, DataList, and Repeater
  • MSPlus - DataList Control
  • MSPlus DataList Control 1.1.0818(个人版) 发布!
  • MSPlus DataList Control(大数据量时的分页演示)
  • datalist或datagrid的数据源是数组的时候怎么写绑定?
  • 【随机文章】
  • J2EE工程实现中常见安全问题解决对策
  • 压缩 NTFS 驱动器
  • 经典签名档
  • WLAN行业应用潜力巨大
  • 改进的IP计数器
  • Flash Action应用--鼠控3D旋转
  • 杭州西湖.湖中音乐喷泉[录象]
  • 用netstat命令发现大量的TIME_WAIT现象
  • 修改Windows XP中的Administrator帐户名
  • Pro*C介绍-内嵌SQL
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.