ASP

本类阅读TOP10

·asp常用数据库连接方法和技巧
·无组件生成BMP验证码
·一些常用的辅助代码 (网络收藏)
·JavaScript实现的数据表格:冻结列、调整列宽和客户端排序
·VisualStudio.NET_2003及其 MSDN 下载地址
·ASP模拟MVC模式编程
·图片以二进制流输出到网页
·MD5加密算法 ASP版
·ASP.NET编程中的十大技巧
·改进 ASP 的字符串处理性能

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
[我的ASP.net学习历程]DataBase Settion(6)

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

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 _172._24._17._134
{
	/// <summary>
	/// WebForm1 的摘要说明。
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label lblChoise;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			string strSql = "SELECT ID,Username,Password,Content,Email,Homepage FROM Table_1";
			string connectionString = "Server=(local);User ID=sa;Pwd=testPass;Database=TestDb;Connect Timeout=5";

			SqlConnection conn = new SqlConnection(connectionString);
			SqlCommand cmd = new SqlCommand(strSql,conn);

			cmd.Connection.Open();

			DataSet ds = new DataSet();
			SqlDataAdapter da = new SqlDataAdapter();

			da.SelectCommand = cmd;

			da.Fill(ds,"Table");

			DataGrid1.DataSource = ds.Tables["Table"].DefaultView;
			DataGrid1.DataBind();

			ds.Clear();
			da.Dispose();
			cmd.Connection.Close();
			cmd.Connection.Dispose();
		}
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.DataGrid1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			TableRow tr = e.Item;
			lblChoise.Text = "您选择的用户是:" + tr.Cells[1].Text;
			lblChoise.Text = lblChoise.Text + " 密码是:" + tr.Cells[2].Text;
			lblChoise.Text = lblChoise.Text + " 内容是:" + tr.Cells[3].Text;
		}
	}
}



相关文章

相关软件