惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
Stack Overflow Blog
Stack Overflow Blog
人人都是产品经理
人人都是产品经理
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Y
Y Combinator Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
博客园 - 司徒正美
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog

博客园 - 物质法则

Direcshow中视频捕捉和参数设置报告-5 Direcshow中视频捕捉和参数设置报告-4 Direcshow中视频捕捉和参数设置报告-3 Direcshow中视频捕捉和参数设置报告-2(转) Direcshow中视频捕捉和参数设置报告-1(转) GridView控件修改、删除示例(修改含有DropDownList控件) - 物质法则 - 博客园 数据层组件设计与数据传递一 自定义实体类简介 css阴影效果 Ajax问题集(不断更新) Start with Ajax.NET 可输入的select JS代码小集合 ajax即时保存 如何访问Formview中的控件 CIU软考联盟:软件设计师试题解析-数据结构篇 CIU软考联盟:软件设计师上午试题解析-操作系统篇 CIU软考联盟:软件设计师(高程)试题解析-软件工程篇 软设考点精要,精确到每页!
GridView的一点用法
物质法则 · 2006-11-30 · via 博客园 - 物质法则

using   System;  
  using   System.Data;  
  using   System.Configuration;  
  using   System.Collections;  
  using   System.Web;  
  using   System.Web.Security;  
  using   System.Web.UI;  
  using   System.Web.UI.WebControls;  
  using   System.Web.UI.WebControls.WebParts;  
  using   System.Web.UI.HtmlControls;  
  using   System.Data.SqlClient;  
   
  public   partial   class   test   :   System.Web.UI.Page  
  {  
          SqlConnection   con;  
          protected   void   Page_Load(object   sender,   EventArgs   e)  
          {  
                  if   (!Page.IsPostBack)  
                  {  
                          Data_Bind();  
                  }  
   
          }  
   
          #region   数据绑定  
   
          private   void   Data_Bind()  
          {  
                  string   str   =   "server=localhost;uid=sa;pwd=;database=lsa_shifang";  
                  con   =   new   SqlConnection(str);  
                  SqlDataAdapter   DA   =   new   SqlDataAdapter("SELECT   *   FROM   TEST_MODEL",   con);  
                  DataSet   ds   =   new   DataSet();  
                  DA.Fill(ds);  
   
                  GridView1.DataSource   =   ds;  
                  GridView1.DataBind();  
                 
          }  
          #endregion  
   
          #region   翻页  
          protected   void   GridView1_PageIndexChanging(object   sender,   GridViewPageEventArgs   e)  
          {  
                  GridView1.PageIndex   =   e.NewPageIndex;  
                  Data_Bind();  
   
          }  
          #endregion  
   
          #region   编辑  
          protected   void   GridView1_RowEditing(object   sender,   GridViewEditEventArgs   e)  
          {  
                  GridView1.EditIndex   =   e.NewEditIndex;  
                  Data_Bind();  
          }  
          #endregion  
          #region   取消  
          protected   void   GridView1_RowCancelingEdit(object   sender,   GridViewCancelEditEventArgs   e)  
          {  
                  GridView1.EditIndex   =   -1;  
                  Data_Bind();  
          }  
          #endregion  
   
          #region   更新  
          protected   void   GridView1_RowUpdating(object   sender,   GridViewUpdateEventArgs   e)  
          {  
                  GridViewRow   gr   =   GridView1.Rows[e.RowIndex];  
                  string   str   =   "server=localhost;uid=sa;pwd=;database=lsa_shifang";  
                  con   =   new   SqlConnection(str);  
                  string   up   =   "update   test_model   set   ask=@ask   where   id=@id";  
                  SqlCommand   com   =   new   SqlCommand(up,   con);  
                  com.Connection.Open();  
                 
                  com.Parameters.AddWithValue("@ask",   SqlDbType.VarChar);  
                  com.Parameters["@ask"].Value   =   ((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).Text.Trim();  
                  com.Parameters.AddWithValue("@id",   SqlDbType.Int);  
                  com.Parameters["@id"].Value   =   ((TextBox)GridView1.Rows[e.RowIndex].Cells[7].Controls[0]).Text.Trim();  
   
                  com.ExecuteNonQuery();  
                  com.Connection.Close();  
                  GridView1.EditIndex   =   -1;  
                  this.Page.RegisterStartupScript("","<SCRIPT>alert('更新成功!')</SCRIPT>");  
                  Data_Bind();  
   
          }  
          #endregion  
   
          #region   删除  
          protected   void   GridView1_RowDeleting(object   sender,   GridViewDeleteEventArgs   e)  
          {  
                  string   str   =   "server=localhost;uid=sa;pwd=;database=lsa_shifang";  
                  con   =   new   SqlConnection(str);  
                  string   del   =   "delete   test_model   where   id=@id";  
                  SqlCommand   com   =   new   SqlCommand(del,   con);  
                  com.Connection.Open();  
                  com.Parameters.AddWithValue("@id",   SqlDbType.Int);  
                  com.Parameters["@id"].Value   =   GridView1.Rows[e.RowIndex].Cells[7].Text;  
                  com.ExecuteNonQuery();  
                  com.Connection.Close();  
                  this.Page.RegisterStartupScript("",   "<SCRIPT>alert('删除成功!')</SCRIPT>");  
                  Data_Bind();  
          }  
          #endregion  
  }  

posted on 2006-11-30 10:17  物质法则  阅读(327)  评论()    收藏  举报