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();

  }

  
 }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Silverlight中DataGrid控件动态生成列并结合DataPager进行分页

1、准备一个实体类 view plaincopy to clipboardprint? using System;  using System.Collections.Generi...

Comobox下拉出DataGrid

  • 2016-07-18 17:25
  • 119KB
  • 下载

flex DataGrid 导出Xls

easyUI datagrid中combobox默认选中问题

以下为本人的个人看法,如有不足请指正: 个人觉得easyUI 的combobox的效率非常低,尤其在ie6下,当然easyUI对ie6的整体兼容性都不怎么样。最近遇到了在datagrid中要将comb...

Flex dataGrid 导入Excel

  • 2015-08-12 12:42
  • 2.06MB
  • 下载

Flex 父窗口监听子窗口关闭并刷新DataGrid

1.父窗口 <![CDATA[ import mx.events.FlexEvent; import mx.events.DragEvent; import mx.ev...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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