• DATALIST里再绑定个DATALIST


     
        一、新建一个aspx文件,在里面加入一个DataList
    0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" border=0>


         第二步,编辑DataList的项模版
    0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" border=0>
        第三步:在项模板的“ItemTemplate”里输入“订单号”、“客户”,并在“客户”后再添加一个DataList。
    0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" border=0>
        第四步:编辑HTML文件,在“订单号”后面添加“<%# DataBinder.Eval(Container.DataItem, "订单ID") %>”;在“客户ID”后面添加“<% # DataBinder.Eval(Container.DataItem, "客户ID") %>”。在“<asp:DataList id="DataList2" runat="server">”和“</asp:DataList>”中间添加“<HeaderTemplate>订单详细</HeaderTemplate><ItemTemplate>产品编号:<%# DataBinder.Eval(Container.DataItem, "产品ID") %>; 单价:<%# DataBinder.Eval(Container.DataItem, "单价") %>; 数量:<%# DataBinder.Eval(Container.DataItem, "数量") %>; 折扣:<%# DataBinder.Eval(Container.DataItem, "折扣") %></ItemTemplate>”
        最后的DataList部分应该是:
    <asp:DataListid="DataList1"runat="server">
         <ItemTemplate>
             <P>订单号:<%# DataBinder.Eval(Container.DataItem, "订单ID") %><BR>
                  客户:<%# DataBinder.Eval(Container.DataItem, "客户ID") %><BR>
                  <asp:DataListid="DataList2"runat="server">
                       <HeaderTemplate>
                           &nbsp; &nbsp; 订单详细
                       </HeaderTemplate>
                       <ItemTemplate>
                           &nbsp; &nbsp; 产品编号:<%# DataBinder.Eval(Container.DataItem, "产品ID") %>;单价:<%# DataBinder.Eval(Container.DataItem, "单价") %>;
                           数量:<%# DataBinder.Eval(Container.DataItem, "数量") %>; 折扣:<%# DataBinder.Eval(Container.DataItem, "折扣") %>;
                       </ItemTemplate>
                  </asp:DataList></P>
         </ItemTemplate>
    </asp:DataList>
        第五步:编辑cs文件。加入“using System.Data.OleDb;”的引用。然后在“private void Page_Load(object sender, System.EventArgs e)”的上面加上“protected OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\\Program Files\\Microsoft Office\\OFFICE11\\SAMPLES\\Northwind.mdb");”
        注意,这里用的是Office2003自带的Northwind.mdb数据库,如果安装的是Office2000的话,路径则为:C:\Program Files\Microsoft Office\OFFICE10\SAMPLES,可自行修改。
     

        第六步:在“private void Page_Load(object sender, System.EventArgs e)”里加上
    string strSql = "select top 10 订单ID,客户ID from 订单 order by 订购日期 desc";
     
    conn.Open();
    OleDbDataAdapter myAdapter = new OleDbDataAdapter(strSql,conn);
    DataSet ds = new DataSet();
    myAdapter.Fill(ds,"ds");
    conn.Close();
     
    this.DataList1.DataSource = ds.Tables[0].DefaultView;
    this.DataList1.DataBind();
     

        如此,绑定了第一个DataList。
        第七步:要绑定DataList里的那个DataList,还要回到aspx页面,选中DataList,在属性项的“ItemDataBound”上双击,然后会自动跳到cs页面
    0 && image.height>0){if(image.width>=700){this.width=700;this.height=image.height*700/image.width;}}" border=0>


     

        第八步:在自动跳转的cs页面的“private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)”下加入以下代码:
    DataRowView drv = (DataRowView)(e.Item.DataItem);
    if (drv!=null)
    {
         DataList DataList2 = (DataList)e.Item.FindControl("DataList2");
         if (DataList2!=null)
         {
             string strSql = "select * from 订单明细 where 订单ID = "+drv["订单ID"].ToString();
             conn.Open();
             OleDbDataAdapter myAdapter = new OleDbDataAdapter(strSql,conn);
             DataSet ds = new DataSet();
             myAdapter.Fill(ds,"ds");
             conn.Close();
             DataList2.DataSource = ds.Tables[0].DefaultView;
             DataList2.DataBind();
         }
    }


    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhangzhenjie518/archive/2008/03/31/2233644.aspx

  • 相关阅读:
    golang mod 导包
    grpc client 报错: code = Unimplemented desc = method *** not implemented
    golang读取email
    docker 使用
    在word中批量更改Mathtype公式的格式
    word中插入myth type公式行距变大的问题
    word中编辑论文公式对齐问题
    向别人学习
    机器学习 博文汇总
    matlab中如何用rand产生相同的随机数
  • 原文地址:https://www.cnblogs.com/mxh691/p/1511371.html
Copyright © 2020-2023  润新知