首页  ·  知识 ·  
Label
      编辑:  图片来源:网络
nodatagrid.aspx
<%@ Page language="c#" Codebehind="nodatagrid.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.nodatagrid" %>


 
  nodatagrid
  
  
  
  
  http://schemas.microsoft.com/intellisense/ie5";;>
 
 
  
   Label
 



nodatagrid.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
 /// 
 /// nodatagrid 的摘要说明。
 /// 
 
 public class nodatagrid : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.Label lb; 

  private string myvar;
  private void Page_Load(object sender, System.EventArgs e)
  {
   try
   {
    if(!IsPostBack)
    {
     myvar="";
     //====建立连接====
     SqlConnection myconn=new SqlConnection("Initial Catalog=Northwind;Data Source=(local);User=sa;password=yourpassword");
     SqlCommand objcmd=new SqlCommand("select top 20 CustomerID,City,Phone from [Customers]",myconn);
     myconn.Open();
     SqlDataReader a=objcmd.ExecuteReader();
     myvar="";
     myvar+="customid";
     myvar+="city";
     myvar+="phone";
     while(a.Read())
     {
      myvar+="";
      myvar+=a[0];
      myvar+="";
      myvar+="";
      myvar+=a[1];
      myvar+="";
      myvar+="";
      myvar+=a[2];
      myvar+="";
      myvar+="";
     }
     myvar+="";
     lb.Text=myvar;
    }
   }
   finally
   {
   }
  }

  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// 
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// 

  private void InitializeComponent()
  {    
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion
 }

}
本文作者:佚名 来源:本站原创
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读
也许感兴趣的
我们推荐的
主题最新
看看其它的
收藏至微信