datagrid

原创 2005年02月27日 16:07: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;
using System.Data.OleDb;
namespace datagrid
{
 /// <summary>
 /// WebForm3 的摘要说明。
 /// </summary>
 public class WebForm3 : 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 datagrid.dsCategories dsCategories1;
  protected System.Web.UI.WebControls.DataGrid DataGrid1;
  protected System.Data.OleDb.OleDbConnection oleDbConnection1;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   oleDbDataAdapter1.Fill(dsCategories1);
   if (!IsPostBack)
   {
    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.dsCategories1 = new datagrid.dsCategories();
   ((System.ComponentModel.ISupportInitialize)(this.dsCategories1)).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("Poster", "Poster")})});
   this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;
   //
   // oleDbSelectCommand1
   //
   this.oleDbSelectCommand1.CommandText = "SELECT ID, Poster FROM Socut_BBS";
   this.oleDbSelectCommand1.Connection = this.oleDbConnection1;
   //
   // oleDbInsertCommand1
   //
   this.oleDbInsertCommand1.CommandText = "INSERT INTO Socut_BBS(Poster) VALUES (?)";
   this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
   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 Poster = ? WHERE (ID = ?) AND (Poster = ? OR ? IS NULL AND P" +
    "oster IS NULL)";
   this.oleDbUpdateCommand1.Connection = this.oleDbConnection1;
   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=""C:/Inetpub/wwwroot/datagrid/socut.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";
   //
   // dsCategories1
   //
   this.dsCategories1.DataSetName = "dsCategories";
   this.dsCategories1.Locale = new System.Globalization.CultureInfo("zh-CN");
   this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
   this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
   this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
   this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
   this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
   this.Load += new System.EventHandler(this.Page_Load);
   ((System.ComponentModel.ISupportInitialize)(this.dsCategories1)).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 = dsCategories1.Socut_BBS.FindByID(int.Parse(key));

   r.Poster = Poster;

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

   DataGrid1.EditItemIndex = -1;

   DataGrid1.DataBind();
   }

  private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
   int aaa;
   aaa = DataGrid1.CurrentRowIndex;
           dsCategories1.Tables[0].Rows[aaa].Delete();

   oleDbDataAdapter1.Update(dsCategories1);
   DataGrid1.DataBind();
  }
  

 

  

  private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
  {
   DataGrid1.CurrentPageIndex =e.NewPageIndex;
   DataGrid1.DataBind();

  }

  
 }
}

easyui datagrid 分页查询样例

  • 2017年08月24日 16:30
  • 993KB
  • 下载

datagrid-groupview.js

  • 2017年10月23日 00:08
  • 3KB
  • 下载

EasyUI--datagrid中编辑器(editor)的类型为combobox的值得绑定

1.绑定固定的值 $(function () { /**管道级别*/ var pipingLevel = [{"value":"1","text":"A级"},{...
  • muyeju
  • muyeju
  • 2015年08月26日 13:39
  • 10945

Flex动态创建DataGrid设置图片

  • 2015年12月16日 14:08
  • 3KB
  • 下载

Comobox下拉出DataGrid

  • 2016年07月18日 17:25
  • 119KB
  • 下载

easyui datagrid中 formatter的用法及失效原因

1.基本用法 单元格formatter(格式化器)函数,带3个参数: value:字段值。 row:行记录数据。 index: 行索引。 $('#dg').da...

flex DataGrid 导出Xls

  • 2016年02月24日 12:21
  • 4KB
  • 下载

Flex dataGrid 表头添加按钮

  • 2015年11月14日 14:43
  • 21KB
  • 下载

datagrid中实现时间调节

时间调节器扩展//时间调节器扩展 $.extend($.fn.datagrid.defaults.editors, { timespinner : { ...

dataGrid中文排序

  • 2013年04月25日 11:00
  • 50KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:datagrid
举报原因:
原因补充:

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