DataGrid综合(无模板列)

原创 2005年03月02日 17:23:00

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;

namespace ooi_cn
{
 /// <summary>
 /// Board 的摘要说明。
 /// </summary>
 public class Board : System.Web.UI.Page
 {
  protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
  protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
  protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
  protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
  protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
  protected System.Data.OleDb.OleDbConnection oleDbConnection1;
  protected ooi_cn.DataSet2 dataSet21;
  protected System.Web.UI.WebControls.DataGrid DataGrid1;
  protected System.Data.OleDb.OleDbCommand oleDbCommand1;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
oleDbDataAdapter1.Fill(dataSet21);
   DataGrid1.DataBind();
  }

  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
   this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
   this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
   this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
   this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
   this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
   this.dataSet21 = new ooi_cn.DataSet2();
   this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand();
   ((System.ComponentModel.ISupportInitialize)(this.dataSet21)).BeginInit();
   //
   // oleDbDataAdapter1
   //
   this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;
   this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;
   this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
   this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
                          new System.Data.Common.DataTableMapping("Table", "Socut_BBS", new System.Data.Common.DataColumnMapping[] {
                                                      new System.Data.Common.DataColumnMapping("ID", "ID"),
                                                      new System.Data.Common.DataColumnMapping("Content", "Content"),
                                                      new System.Data.Common.DataColumnMapping("Poster", "Poster")})});
   this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;
   //
   // oleDbSelectCommand1
   //
   this.oleDbSelectCommand1.CommandText = "SELECT ID, Content, Poster FROM Socut_BBS ORDER BY ID DESC";
   this.oleDbSelectCommand1.Connection = this.oleDbConnection1;
   //
   // oleDbInsertCommand1
   //
   this.oleDbInsertCommand1.CommandText = "INSERT INTO Socut_BBS(Content, Poster) VALUES (?, ?)";
   this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
   this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Content", System.Data.OleDb.OleDbType.VarWChar, 0, "Content"));
   this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Poster", System.Data.OleDb.OleDbType.VarWChar, 50, "Poster"));
   //
   // oleDbUpdateCommand1
   //
   this.oleDbUpdateCommand1.CommandText = "UPDATE Socut_BBS SET Content = ?, Poster = ? WHERE (ID = ?) AND (Poster = ? OR ? " +
    "IS NULL AND Poster IS NULL)";
   this.oleDbUpdateCommand1.Connection = this.oleDbConnection1;
   this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Content", System.Data.OleDb.OleDbType.VarWChar, 0, "Content"));
   this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Poster", System.Data.OleDb.OleDbType.VarWChar, 50, "Poster"));
   this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ID", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ID", System.Data.DataRowVersion.Original, null));
   this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Poster", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Poster", System.Data.DataRowVersion.Original, null));
   this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Poster1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Poster", System.Data.DataRowVersion.Original, null));
   //
   // oleDbDeleteCommand1
   //
   this.oleDbDeleteCommand1.CommandText = "DELETE FROM Socut_BBS WHERE (ID = ?) AND (Poster = ? OR ? IS NULL AND Poster IS N" +
    "ULL)";
   this.oleDbDeleteCommand1.Connection = this.oleDbConnection1;
   this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ID", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ID", System.Data.DataRowVersion.Original, null));
   this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Poster", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Poster", System.Data.DataRowVersion.Original, null));
   this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Poster1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Poster", System.Data.DataRowVersion.Original, null));
   //
   // oleDbConnection1
   //
   this.oleDbConnection1.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source=""F:/1web/ooi_cn/#ooicn.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";
   //
   // dataSet21
   //
   this.dataSet21.DataSetName = "DataSet2";
   this.dataSet21.Locale = new System.Globalization.CultureInfo("zh-CN");
   //
   // oleDbCommand1
   //
   this.oleDbCommand1.Connection = this.oleDbConnection1;
   this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
   this.Load += new System.EventHandler(this.Page_Load);
   ((System.ComponentModel.ISupportInitialize)(this.dataSet21)).EndInit();

  }
  #endregion

  private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
   DataGrid1.EditItemIndex = e.Item.ItemIndex;
   DataGrid1.DataBind();

  }

  private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
   DataGrid1.EditItemIndex = -1;
   DataGrid1.DataBind();

  }

  private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
   string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();

   string Poster;
  
   TextBox tb;
   tb = (TextBox) e.Item.Cells[2].Controls[0];
   Poster = tb.Text;

   dsCategories.Socut_BBSRow r;
   r = dataSet21.Socut_BBS.FindByID(int.Parse(key));

   r.Poster = Poster;

   oleDbDataAdapter1.Update(dataSet21);
   DataGrid1.DataBind();

   DataGrid1.EditItemIndex = -1;

   DataGrid1.DataBind();
  }

  private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
   string delCmd="delete from SOCUT_BBS where ID="+DataGrid1.DataKeys[(int)e.Item.ItemIndex].ToString();
   oleDbCommand1.CommandText=delCmd;
   oleDbCommand1.Connection.Open();
   oleDbCommand1.ExecuteNonQuery();
   oleDbCommand1.Connection.Close();
   oleDbDataAdapter1.Fill(dataSet21);
   DataGrid1.EditItemIndex=-1;
   DataGrid1.DataBind();
  }
 }
}

相关文章推荐

datagrid动态添加模板列

  • 2012年08月10日 11:37
  • 236KB
  • 下载

DataGrid模板列自定义控件

  • 2014年12月24日 10:37
  • 60KB
  • 下载

在DataGrid里面绑定ComboBox列时无法在编辑模板下默认选中一个备选值的一种解决方法

今天同事遇到一个关于DataGrid模板列里添加一个ComboBox控件的问题。 大致的情景如下面的截图所示: William的性别是Male,但是当双击性别列(它是一个带有ComboBo...
  • Neils03
  • Neils03
  • 2013年01月30日 13:08
  • 1646

动态创建模板列并绑定数据(GridView,Repeater,DataGrid)

动态创建模板列并绑定数据(GridView,Repeater,DataGrid) 要创建动态模板,请创建以后需要时可实例化的模板类。 创建模板类 创建实现 System....

编写 WPF DataGrid 列模板,实现更好的用户体验

DatePicker 和新的 DataGrid 行 用户与 DataGrid 中日期列的交互给我造成了很大的麻烦。 我通过将一个 Data Source 对象拖动到 WPF 窗口上,创建了一个...

DataGrid一个综合的例子

  • 2010年07月02日 08:47
  • 140KB
  • 下载

easyui datagrid综合功能demo实现

EasyUI行内批量修改和添加Demo实现

SilverLight ---动态生成DataGrid,动态绑定DataGrid模板列--With LinQ

是在参看了这篇文章 后 觉得不错,然后修改成用linq方法来实现的,全部代码如下 using System; using System.Collections.Generic; using Sy...

DataGrid模板js配置

$("#dg").datagrid({ url:'/org/getImportLogs', striped:true, autoRowHeight : false, t...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:DataGrid综合(无模板列)
举报原因:
原因补充:

(最多只允许输入30个字)