CSDN博客

img dhz123

明细表2---浮动

发表于2004/10/25 14:46:00  671人阅读

分类: Asp.net

<%@ Import Namespace="System.Data" %> <%@ Page language="c#" Codebehind="master_Detail2.aspx.cs" AutoEventWireup="false" Inherits="常用界面.master_Detail2" %>

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 常用界面
{
 /// <summary>
 /// master_Detail2 的摘要说明。
 /// </summary>
 public class master_Detail2 : System.Web.UI.Page
 {
  protected System.Data.SqlClient.SqlConnection sqlConnection1;
  protected System.Web.UI.WebControls.Repeater childRepeater;
  protected System.Web.UI.WebControls.DataGrid mGrid;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   if(!Page.IsPostBack)
   {
    this.repeaterBind(true);
    //this.mGrid.Attributes["onclick"]="hideAll()";
   }
  }

  private void  repeaterBind(bool fr)
  {
   if(fr)
   {
    SqlCommand cmd=new SqlCommand("select EmployeeID,lastName,firstName,Address,City from  employees;select OrderID,EmployeeID,OrderDate,ShipName from  orders",this.sqlConnection1 );
    SqlDataAdapter da=new SqlDataAdapter(cmd);
    da.TableMappings.Add("Table","Emp");
    da.TableMappings.Add("Table1","Ord");
    DataSet ds=new DataSet("M_S");
    da.Fill(ds);
    ds.Relations.Add("Emp_Ord",ds.Tables["Emp"].Columns["EmployeeID"],ds.Tables["Ord"].Columns["EmployeeID"]);
       this.mGrid.DataSource=ds.Tables["Emp"].DefaultView ;
    this.mGrid .DataBind ();
    
   }
   else
   {
     DataSet dc=Cache["MD_Emp_Ord"] as DataSet ;
     this.mGrid.DataSource=dc.Tables["Emp"].DefaultView ;
     this.mGrid .DataBind ();
    
   }
  }
  private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
   if(e.Item.ItemType==ListItemType.Item)
   {
    foreach(TableCell cl in e.Item.Cells )
    {
     cl.Attributes["valign"]="top";
    }
   }
  }
  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
   //
   // sqlConnection1
   //
   this.sqlConnection1.ConnectionString = "workstation id=DHZ;packet size=4096;integrated security=SSPI;data source=DHZ;pers" +
    "ist security info=False;initial catalog=Northwind";
   this.Load += new System.EventHandler(this.Page_Load);
   this.mGrid.ItemDataBound+=new DataGridItemEventHandler(this.DataGrid1_ItemDataBound );

  }
  #endregion
 }
}

0 0

相关博文

我的热门文章

img
取 消
img