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

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

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

ASP.NET中为DataGrid动态创建模板列

 为DataGrid动态创建模板列,首先要实现ITemplate接口:public class MyDataGridTemplate : System.Web.UI.ITemplate...{    ...
  • junchieh
  • junchieh
  • 2007年03月09日 23:43
  • 834

Asp.Net中DataGrid的模版列(TemplateColumn)内容控制简单方法。

最近写了几个asp.net的项目。其中,Asp.Net的控件DataGrid使用的最多了,前几天需要一个功能,我研究了很长时间,发现一个方法,应该是最简单的实现。现表述如下。 DataGrid的htm...
  • TomMax
  • TomMax
  • 2004年12月16日 19:40
  • 3078

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

    很长一段时间中,不管是使用DataGrid 还是GridView都是通过拖放的方式。而这两天有个需求必须使用自定义的GridView,动态创建GridView的Columns,折腾了数小时,终...
  • llxchen
  • llxchen
  • 2008年01月18日 12:09
  • 7691

asp.net中DataGrid双行跨列表头设计心得!

asp.net中DataGrid双行跨列表头设计心得! 一、DataGrid的属性设置   1. AllowPaging: true   2. PageStyle->Position: TopAndB...
  • yfm10
  • yfm10
  • 2009年07月03日 18:43
  • 1541

ASP.NET中如何动态生成模板列

///  /// 实现ITemplate接口,用来打印 ///  public class ColumnTemplate : ITemplate {      public void Instanti...
  • minghui000
  • minghui000
  • 2005年04月03日 10:53
  • 960

easyUI datagrid最后操作列的实现总结

使用easyUI的童鞋们大多都会发现,通常在数据遍历完成后,无法在最后一列做相关操作,虽然easyUI本身有自己的增删改查按钮 ,但有时候为了美观,通常将操作放在最后一列来实现。 好了,废话不多说,...
  • qq_27298687
  • qq_27298687
  • 2015年08月05日 16:21
  • 2788

WPF设置DataGrid列的标题格式

zai                            TargetType="{x:Type TextBlock}">
  • xiaogang06141111
  • xiaogang06141111
  • 2014年05月21日 14:18
  • 2122

WPF-DataGrid后台动态生成列

DataGrid后台动态生成列 Now that you know the basics of the Silverlight DataGrid and how to specify...
  • yqj234
  • yqj234
  • 2016年03月14日 15:49
  • 5107

asp.Net中Gridview动态创建模板列 .

Web中有时候数据源字段不确定,需要在绑定后添加新的字段,有没有方法了?方法是有的:之前也在网上搜索过,找到了一些方法,通过模板列可以实现。这里借鉴一下,自己亲自试验了一下,达到了想要的效果。 Gr...
  • LzShmily
  • LzShmily
  • 2013年02月05日 15:22
  • 496
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:DataGrid综合(无模板列)
举报原因:
原因补充:

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