UltraWebGrid增删改(c#)

using   System;
using   System.Data;
using   System.Configuration;
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;
using   Infragistics.WebUI.UltraWebGrid;
using   System.Data.SqlClient;

public   partial   class   _Default   :   System.Web.UI.Page  
{
        private   DataSet   ds   =   new   DataSet();
        private   SqlCommand   SelectCommand1;
        private   SqlCommand   InsertCommand1;
        private   SqlCommand   UpdateCommand1;
        private   SqlCommand   DeleteCommand1;
        private   SqlConnection   con;
        private   SqlDataAdapter   da;

        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                this.GetData();
             
                if   (!this.IsPostBack)
                        this.UltraWebGrid1.DataBind();
        }

        private   void   GetData()
        {
                con   =   new   SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[ "RegPwdConnectionString "].ConnectionString);
                this.SelectCommand1   =   new   SqlCommand();
                this.SelectCommand1.CommandText   =   "SELECT   *   FROM   mjn_vn_Users ";
                this.SelectCommand1.Connection   =   con;
                this.da   =   new   SqlDataAdapter();
                this.da.SelectCommand   =   this.SelectCommand1;
                da.Fill(ds, "users ");
                ds.Tables[0].PrimaryKey   =   new   DataColumn[]   {   ds.Tables[0].Columns[ "CustomerID "]   };
                 
        }
        protected   void   UltraWebGrid1_DataBinding(object   sender,   EventArgs   e)
        {
                this.UltraWebGrid1.DataSource   =   ds.Tables[ "users "];
        }
        protected   void   UltraWebGrid1_InitializeLayout(object   sender,   Infragistics.WebUI.UltraWebGrid.LayoutEventArgs   e)
        {
                e.Layout.AllowUpdateDefault   =   AllowUpdate.Yes;
                e.Layout.AllowAddNewDefault   =   AllowAddNew.Yes;
                e.Layout.AddNewBox.Hidden   =   false;
                e.Layout.HeaderStyleDefault.HorizontalAlign   =   HorizontalAlign.Center;
                e.Layout.Bands[0].DataKeyField   =   "CustomerID ";
                this.UltraWebGrid1.Bands[0].Columns.FromKey( "CustomerID ").Hidden   =   true;
                this.UltraWebGrid1.Bands[0].Columns.FromKey( "CustomerNo ").Header.Caption= "用户编号 ";
                this.UltraWebGrid1.Bands[0].Columns.FromKey( "CustomerPwd ").Header.Caption   =   "用户密码 ";
                this.UltraWebGrid1.Bands[0].Columns.FromKey( "Email ").Header.Caption   =   "用户邮箱 ";
                this.UltraWebGrid1.Bands[0].Columns.FromKey( "Status ").Header.Caption   =   "状态 ";
                this.UltraWebGrid1.Bands[0].Columns.FromKey( "Status ").CellStyle.HorizontalAlign   =   HorizontalAlign.Center;
                this.UltraWebGrid1.Bands[0].Columns.FromKey( "Status ").Width   =   40;
                this.UltraWebGrid1.Bands[0].Columns.FromKey( "CreateDate ").Header.Caption   =   "创建时间 ";
               
        }
        protected   void   UltraWebGrid1_UpdateRowBatch(object   sender,   Infragistics.WebUI.UltraWebGrid.RowEventArgs   e)
        {
             
                UltraGridRow   oldRow   =   (UltraGridRow)e.Data;
                string   dataKey   =   e.Row.DataKey.ToString();
                switch   (e.Row.DataChanged)
                {
                        case   (DataChanged.Added):
                                DataRow   newDataTableRow   =   ds.Tables[ "Customers "].NewRow();
                                foreach   (UltraGridCell   c   in   e.Row.Cells)
                                {
                                        newDataTableRow[c.Column.Key]   =   c.Value;
                                        Response.Write(c.Value.ToString()+ " <br> ");
                                }
                                ds.Tables[0].Rows.Add(newDataTableRow);
                                e.Row.DataKey   =   e.Row.Cells.FromKey( "CustomerID ").Value;
                                break;
                        case   (DataChanged.Modified):
                                if   (dataKey!=null)
                                {
                                        DataRow   dr   =   ds.Tables[0].Rows.Find(new   object[]   {   dataKey   });
                                        if   (dr   !=   null)
                                        {
                                                foreach   (UltraGridCell   c   in   e.Row.Cells)
                                                {
                                                        if   (!dr[c.Column.Key].Equals(c.Value))
                                                        {
                                                                dr[c.Column.Key]   =   c.Value;
                                                                Response.Write(dr[c.Column.Key].ToString()+ " <br> ");
                                                        }
                                                }
                                        }
                                        e.Row.DataKey   =   e.Row.Cells.FromKey( "CustomerID ").Value;
                                }
                                break;
                }
        }
        protected   void   Button1_Click(object   sender,   EventArgs   e)
        {

                con   =   new   SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[ "RegPwdConnectionString "].ConnectionString);
                this.InsertCommand1   =   new   SqlCommand();
                this.InsertCommand1.CommandText   =   "Insert   into   mjn_vn_Users(CustomerNo,CustomerPwd,Email)   Values(?,?,?) ";
                this.InsertCommand1.Connection   =   con;

                this.InsertCommand1.Parameters.Add(new   System.Data.SqlClient.SqlParameter( "CustomerNo ",   System.Data.SqlDbType.NVarChar,   50,   "CustomerNo "));
                this.InsertCommand1.Parameters.Add(new   System.Data.SqlClient.SqlParameter( "CustomerPwd ",   System.Data.SqlDbType.NVarChar,   50,   "CustomerPwd "));
                this.InsertCommand1.Parameters.Add(new   System.Data.SqlClient.SqlParameter( "Email ",   System.Data.SqlDbType.NVarChar,   50,   "Email "));

                this.UpdateCommand1   =   new   SqlCommand();
                this.UpdateCommand1.CommandText   =   "Update   mjn_vn_Users   SET   CustomerNo=?,CustomerPwd=?,Email=?   where   CustomerID=   ? ";
                this.UpdateCommand1.Connection   =   con;

                this.UpdateCommand1.Parameters.Add(new   System.Data.SqlClient.SqlParameter( "CustomerNo ",   System.Data.SqlDbType.NVarChar,   50,   "CustomerNo "));
                this.UpdateCommand1.Parameters.Add(new   System.Data.SqlClient.SqlParameter( "CustomerPwd ",   System.Data.SqlDbType.NVarChar,   50,   "CustomerPwd "));
                this.UpdateCommand1.Parameters.Add(new   System.Data.SqlClient.SqlParameter( "Email ",   System.Data.SqlDbType.NVarChar,   50,   "Email "));
                this.UpdateCommand1.Parameters.Add(new   System.Data.SqlClient.SqlParameter( "CustomerID ",   System.Data.SqlDbType.BigInt,   8,   "CustomerID "));

                this.da.InsertCommand   =   this.InsertCommand1;

                this.da.TableMappings.AddRange
                (
                        new   System.Data.Common.DataTableMapping[]  
                        {
                                new   System.Data.Common.DataTableMapping
                                ( "Table ",   "Customers ",  
                                      new   System.Data.Common.DataColumnMapping[]  
                                      {
                                                  new   System.Data.Common.DataColumnMapping( "CustomerID ",   "CustomerID "),
                                                  new   System.Data.Common.DataColumnMapping( "CustomerNo ",   "CustomerNo "),
                                                  new   System.Data.Common.DataColumnMapping( "CustomerPwd ",   "CustomerPwd "),
                                                  new   System.Data.Common.DataColumnMapping( "Email ",   "Email ")
                                      }
                                )
                          }
                );

                this.da.UpdateCommand   =   this.UpdateCommand1;
        }
        protected   void   UltraWebGrid1_UpdateGrid(object   sender,   UpdateEventArgs   e)
        {
                if   (ds.HasChanges())
                {
                        try
                        {
                           
                                da.Update(ds.Tables[ "Table "]);
                        }
                        catch   (Exception   ex)
                        {
                                Response.Write( "出错!! "+ex.Message);
                        }
                }
       
        }
}  
本控件是基于Asp.Net平台的Web表格控件,用于Web网站的开发。 ★支持多种浏览器(IE6以上、FireFox2.0以上、谷歌浏览器等)。 ★使用本控件开发的网站,网页上表格的插入、追加、删除、修改、上下移动、拷贝、粘贴等操作,能够立即在浏览器客户端完成,操作按钮在上图表格的左下部。 ★提交后的数据为一个DataTable。用户可使用GetCommitData方法取得使用本控件,很好地节约了网络资源,提升了网站的多用户对应能力。极大地提高了网页的反应速度,提升了网站浏览者的浏览体验。 ★本控件提供了丰富的自定义样式,供开发人员设定使用。表格(GridStyle)、奇偶(ItemStyle、AlternatingItemStyle)、列(列的ItemStyle)、列内的控件(列的ControlStyle)、合计(PageTotalStyle、AllTotalStyle)、控制(包含各种操作按钮和页操作按钮ToolBarStyle)都可以自由的进样式设定。 ★提供多种类型的列供开发人员使用:(LabelColumn(图A-金额),TextBoxColumn(图A-数量、单价),DropDownListColumn(图A-类别、商品),RadioButtonListColumn(图A-发货区分),CheckBoxColumn(图A-包装有无),RowIndexColumn(图A-ID),HiddenColumn(隐藏列),TemplateColumn(图A-备注,模板,用于扩展)。 ★支持多表头显示(图A),支持列合并(图A-发货区分)、合并(图A-备注)。使用本控件进开发,开发人员能够自由设定各种显示效果。 ★支持开发人员自定义表头。 ★支持一个数据,多表格表示。避免了列项目多的情况下,网页显示过宽的问题。(图A) ★支持金额、数字的自定义格式化功能。(图A-数量、单价,金额,金额美元) ★支持货币符号的自定义(如:$,¥)。(图A-金额,金额美元) ★支持列的公式自动计算功能。(图A-金额=数量×单价,金额美元=金额/汇率)列设定公式后,在网页上根据因子的变化自动计算结果。结合金额、数字的自定义格式化和货币符号的自定义功能,可开发专业性的财会、金融网站。 ★支持列的Ajax联动功能。特别定义了OnCallBack事件,开发人员能非常简单地实现Ajax联动,而页面不需要刷新。(图A-类别变化的时候,Ajax联动,更新了图A-商品列表) ★支持模板列(TemplateColumn),(图A-备注,模板)。并支持模板列的Ajax联动功能。模板列提供了扩展功能,使页面可以使用本控件支持的列类型之外的控件类型。 ★支持自定义分页(图A定义每页大小为3)。可由开发人员自决定网页提交的模式,是小批量多批次,还是大批量少批次。本控件的灵活性提高了网站的灵活适应性。 ★本控件自动提供自带的分页控件,提供页的导航功能(图A右下部)。开发人员也可以禁止本控件提供的分页控件,使用自己的分页控件或按钮调用本控件的分页功能。 ★表格的上下移动功能,在分页的情况下,当需要跨页的情况下,自动提交数据,执RowMoving事件,开发者可以在此事件中执真正的数据的上下移动,再绑定显示数据。 ★表格的拷贝、粘贴功能,在分页的情况下,支持跨页执,支持带Ajax联动列的直接拷贝。 ★支持操作的撤销、恢复功能,提升用户操作体验。 ★支持页合计和全部页合计。支持五种合计类型(Sum,Max,Min,Count,Average)。通过简单的开关设置,就可以完成合计功能。(图A-数量、金额、金额美元,设定了Sum合计;图A-单价,设定了Average合计)。 ★支持多种数据源。 ★所见即所得的设计时支持,方便软件开发者进页面设计。 ★提供丰富、实用的JS接口,供开发人员使用。 ★本控件的开发中,力求功能的简洁、实用、耐用。提升开发人员的开发体验。 QQ:1030032915 MSN:IntelliGrid@hotmail.com
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值