[我的ASP.net学习历程]DataBase Settion(6)
2004-09-24 09:04
351 查看
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; } } }
相关文章推荐
- [我的ASP.net学习历程]DataReader(2)
- [我的ASP.net学习历程]编码转换
- [我的ASP.net学习历程]DataBase Settion(4)
- asp.net个人学习历程初学到精通 收藏
- [我的ASP.net学习历程]DropDownList
- [我的ASP.net学习历程]服务器环境检测
- [我的ASP.net学习历程]DataBase Settion(5)
- [ASP.net学习历程]调用类库函库的简单加密方法
- [导入]ASP.NET 学习历程
- [我的ASP.net学习历程]Hashtable(DataBind)
- [我的ASP.net学习历程]类型转换
- [我的ASP.net学习历程]DataBase Settion(7)
- [我的ASP.net学习历程]有关于.dll文件的迷惑
- [我的ASP.net学习历程]编码转换http://www.21tx.com/dev/2004/09/21/12011.html
- [我的ASP.net学习历程]ImageStream图像数据流
- [我的ASP.net学习历程]数据梆定
- .Asp.Net 2.0 学习历程 菜鸟到中级程序员的飞跃
- asp.net ajax学习历程(一)
- [我的ASP.net学习历程]IsPostBack
- [我的ASP.net学习历程]数据库操作(一)