初见,Devexpress
1.连接数据库
class="code_img_closed" src="/Upload/Images/2013090323/0015B68B3C38AA5B.gif" alt="" />logs_code_hide('aef6980e-0b69-47ce-9d8c-9078a1fc8b70',event)" src="/Upload/Images/2013090323/2B1B950FA3DF188F.gif" alt="" />1 using System; 2 using System.Collections.Generic; 3 using System.Web; 4 using System.Data.OleDb; 5 6 namespace myBPB 7 { 8 public class myDB 9 { 10 OleDbConnection conn = null; 11 public OleDbConnection getConn() 12 { 13 string sServer = "192.168.132.10"; 14 string sDatabase = "myBPB"; 15 string sUser = "sa"; 16 string sPassword = "12345678"; 17 //Provider=SQLOLEDB; 指的是连接数据库所用的相关数据库驱动 18 //Data Source; 指的是服务器地址或服务器名称 19 //Persist Security Info; 指的是是否保存安全信息,其实可以简单的理解为"在数据库连接成功后是否保存密码信息",True表示保存,False表示不保存 20 //Initial Catalog; 指的是要连接的数据库名称 21 //User ID; 登录数据库的名称 22 //Password; 登录数据库的密码 23 String sSQL = String.Format("Provider=SQLOLEDB;Data Source={0};" +"Persist Security Info=True;User ID={2};" +"Initial Catalog={1};Password={3};",sServer, sDatabase, sUser, sPassword);//数据库连接语句 24 try 25 { 26 conn = new OleDbConnection(sSQL); 27 conn.Open(); 28 return conn; 29 } 30 catch (System.Exception ex) 31 { 32 return null; 33 } 34 } 35 } 36 }连接数据库
2.填充ASPxGridView
1 public void BindGridView() 2 { 3 OleDbConnection conn = new myDB().getConn(); 4 string str = "select * from 区域"; 5 OleDbDataAdapter da = new OleDbDataAdapter(str, conn); 6 DataSet ds = new DataSet(); 7 da.Fill(ds); 8 this.ASPxGridView1.DataSource = ds.Tables[0].DefaultView; 9 this.ASPxGridView1.DataBind(); 10 conn.Close(); 11 }填充ASPxGridView
3.布局
控件:ASPxSplitter(分离器)
作用:布局时多用于分割页面
属性:Orientation(方向)= Vertical(垂直)或 Herizontal(水平)
ASPxSplitter1.Panes[0].PaneStyle.Paddings.Padding = 0; //第一个面板的内边距为0
ASPxSplitter1.Panes[1].PaneStyle.Paddings.Padding = 0; //第二个面板的内边距为0
ASPxSplitter1.Panes[0].Size = 63; //第一个面板的高度(大小)为63
ASPxSplitter1.Panes[1].ScrollBars = ScrollBars.Auto; //自动出现滚动条
ASPxSplitter1.AllowResize = false; //不允许调整ASPxSplitter1
ASPxSplitter1.FullscreenMode = true; //全屏模式为true
控件:ASPxMenu1(菜单)
作用:制作菜单
属性:width(宽度)=100%
Items(菜单的选项)
ItemAutoWidth(菜单选项宽度自动调整)=True(真)或False(假)
AutoSeparators="RootOnly"(菜单选项之间用竖线隔开)
ClientInstanceName="ASPxMenu1"(控件的前端名称)
控件:表格
作用:排版
属性:Style—>表格—>table-layout=fixed(表格宽度为固定值)
控件:ASPxImage
作用:显示图标、图片
属性:ASPxImage1.ImageUrl = "~/Images/man.gif";
控件:ASPxGridView
作用:显示数据
属性:ASPxGridView1.Width = 2000;
ASPxGridView1.SettingsBehavior.AllowFocusedRow = true;//每行都可以选择
Columns(列)— Caption(显示名称)— FieldName(数据库连接字段)
AutoGenerateColumns="False"//数据源自动绑定为假
KeyFieldName="bh"//关键字为bh
ClientInstanceName="ASPxGridView1"(控件的前端名称)
前端运用:
1.在每行前面添加一个ASPxCheckBox
1 <dx:ASPxGridView ID="ASPxGridView1" runat="server"> 2 <Columns> 3 4 <dx:GridViewCommandColumn Caption="操作" ShowSelectCheckbox="true" VisibleIndex="0" Width="20px"> 5 <HeaderTemplate> 6 <dx:ASPxCheckBox ID="ASPxCheckBox1" runat="server" ToolTip="Select/Unselect all rows on the page" 7 ClientSideEvents-CheckedChanged="function(s, e) { ASPxGridView1.SelectAllRowsOnPage(s.GetChecked()); }" /> 8 </HeaderTemplate> 9 </dx:GridViewCommandColumn> 10 11 </Columns> 12 </dx:ASPxGridView>自动添加ASPxCheck.xml
2.在第一列显示行号
1 <dx:ASPxGridView ID="ASPxGridView1" runat="server"> 2 <Columns> 3 4 <dx:GridViewDataTextColumn Caption="序号" FieldName="XH" UnboundType="Integer" VisibleIndex="0"Width="36px"> 5 <Settings AutoFilterCondition="Contains" /> 6 <CellStyle HorizontalAlign="Center"> 7 </CellStyle> 8 </dx:GridViewDataTextColumn> 9 10 </Columns> 11 </dx:ASPxGridView>自动添加行号.xml
1 protected void ASPxGridView1_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs e) 2 { 3 if (e.Column.FieldName == "XH" && e.IsGetData) 4 e.Value = (e.ListSourceRowIndex + 1).ToString(); 5 }自动添加行号.后台
3.将Columns分组
1 <dx:GridViewBandColumn Caption="使用于"> 2 <Columns> 3 <dx:GridViewDataTextColumn Caption="部门" FieldName="部门" 4 ShowInCustomizationForm="True" VisibleIndex="9" Width="150px"> 5 <Settings AutoFilterCondition="Contains" /> 6 </dx:GridViewDataTextColumn> 7 <dx:GridViewDataTextColumn Caption="何工序或何设备" FieldName="何工序或何设备" 8 ShowInCustomizationForm="True" VisibleIndex="11" Width="200px"> 9 <Settings AutoFilterCondition="Contains" /> 10 </dx:GridViewDataTextColumn> 11 </Columns> 12 </dx:GridViewBandColumn>Columns.xml
4.ASPxComboBox配置数据源
1 <asp:SqlDataSource ID="SqlDataSource1_BuMen" runat="server" 2 ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 3 ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 4 SelectCommand="SELECT DISTINCT [部门名称], [部门编码] FROM [部门设置]"></asp:SqlDataSource>数据源—部门.xml
1 <dx:ASPxComboBox ID="Com_BuMen" runat="server" 2 DataSourceID="SqlDataSource1_BuMen" ValueField="部门编码" DropDownStyle="DropDownList" 3 ValueType="System.String" TextFormatString="{1}" EnableCallbackMode="true" 4 IncrementalFilteringMode="Contains" TextField="部门编码" 5 ClientInstanceName="Com_BuMen" > 6 <Columns> 7 <dx:ListBoxColumn FieldName="部门编码" Width="45px" /> 8 <dx:ListBoxColumn FieldName="部门名称" Width="100%" /> 9 </Columns> 10 </dx:ASPxComboBox>部门文本框.前台
5.增加
1 public void Add() 2 { 3 String str_add= "insert into 区域(区域号,区域,备注) values('" + QuYuHao + "','" + QuYu + "','" + BeiZhu + "')"; 4 OleDbConnection conn = new myDB().getConn(); 5 OleDbCommand com = new OleDbCommand(str_add, conn); 6 if(Convert.ToInt32(com.ExecuteNonQuery())>0) 7 { 8 Page.ClientScript.RegisterClientScriptBlock(typeof(QuYuEdit), "CustomEdit", "alert('添加成功!!');", true); 9 } 10 else 11 { 12 Page.ClientScript.RegisterClientScriptBlock(typeof(QuYuEdit), "CustomEdit", "alert('添加失败!!');", true); 13 } 14 conn.Close(); 15 }增加.后台
6.删除
1 public void Del() 2 { 3 String str_Del = "delete from 区域 where bh=" + 3; 4 OleDbConnection conn = new myDB().getConn(); 5 OleDbCommand com = new OleDbCommand(str_Del, conn); 6 int counts = com.ExecuteNonQuery(); 7 if (counts > 0) 8 { 9 Page.ClientScript.RegisterClientScriptBlock(typeof(WuLiaoBianMa), "CustomEdit", "alert('删除成功!');", true); 10 } 11 else 12 { 13 Page.ClientScript.RegisterClientScriptBlock(typeof(WuLiaoBianMa), "CustomEdit", "alert('删除失败!');", true); 14 } 15 conn.Close(); 16 }删除.后台
7.修改
1 public void Update() 2 { 3 String str_Update = "update 区域 set 区域号='" + QuYuHao + "',区域='" + QuYu + "',备注='" + BeiZhu + "' where bh=" + Convert.ToInt32(ASPxHiddenField1.Get("SBH1")); 4 OleDbConnection conn = new myDB().getConn(); 5 OleDbCommand com = new OleDbCommand(str_Del, conn); 6 int counts = com.ExecuteNonQuery(); 7 if (counts > 0) 8 { 9 Page.ClientScript.RegisterClientScriptBlock(typeof(WuLiaoBianMa), "CustomEdit", "alert('修改成功!');", true); 10 } 11 else 12 { 13 Page.ClientScript.RegisterClientScriptBlock(typeof(WuLiaoBianMa), "CustomEdit", "alert('修改失败!');", true); 14 } 15 conn.Close(); 16 }修改.后台
8.查询
1 public String Old_Name() 2 { 3 OleDbConnection conn = new myDB().getConn(); 4 string str = "select * from 物料编码 where bh='" + Convert.ToInt32(ASPxHiddenField1.Get("sBH")) + "'"; 5 OleDbDataAdapter da = new OleDbDataAdapter(str, conn); 6 DataSet ds = new DataSet(); 7 da.Fill(ds); 8 String m = ds.Tables[0].Rows[0]["物料编码"].ToString(); 9 return m; 10 }查询(DataAdapter、DataSet).后台
1 public void Lei_Xing() 2 { 3 OleDbConnection conn = new myDB().getConn(); 4 string str = "select * from 基础数据 where 目录='供应商类型'"; 5 OleDbCommand com = new OleDbCommand(str, conn); 6 OleDbDataReader read = com.ExecuteReader(); 7 while (read.Read()) 8 { 9 Txt_LeiXing.Items.Add(read["内容"].ToString()); 10 } 11 }查询后台(DataReader).后台
9.ASPxGridView中勾选ASPxCheckBox删除数据
1 List<object> keyValues = this.ASPxGridView1.GetSelectedFieldValues("bh"); //需要在ASPxGridView1的源设置 KeyFieldName="bh" 2 ASPxGridView1.Selection.UnselectAll(); //清空ASPxGridView中所有选择的语句。 3 int count = keyValues.Count; 4 if (str == "删除") 5 { 6 if (count <= 0) 7 { 8 Page.ClientScript.RegisterClientScriptBlock(typeof(WuLiaoBianMa), "CustomEdit", "alert('请选择要删除的数据!');", true); 9 return; 10 } 11 foreach (object key in keyValues) 12 { 13 do_del(key.ToString()); //删除 14 } 15 keyValues.Clear(); 16 count = keyValues.Count; 17 BindGridView(); 18 }ASPxGridView中勾选ASPxCheckBox删除数据
10.ASPxGridView过滤
后台:ASPxGridView1.Settings.ShowFilterRow = true; 前台:<Settings AutoFilterCondition="Contains" /> //ASPxGridView属性—>Columns—>要实现过滤的列—>Settings—>AutoFilterCondition="Contains"
11.ASPxGridViewExporter导出
1 if (Directory.Exists(Server.MapPath("tmp")) == false) 2 { 3 Directory.CreateDirectory(Server.MapPath("tmp")); 4 } 5 string path = Server.MapPath("~/tmp/");//获取完整路径 6 ASPxGridViewExporter1.FileName = "物料编码"; 7 ASPxGridViewExporter1.PageHeader.Font.Size = 14; 8 string message1 = @"物料编码"; 9 ASPxGridViewExporter1.PageHeader.Center = message1; 10 this.ASPxGridViewExporter1.WriteXlsToResponse();ASPxGridViewExporter导出.后台
12.ASPxHiddenField隐藏字段
设置前台名称:ClientInstanceName="hf1"; 后台赋初值:ASPxHiddenField1.Add("SBH",0); 前台赋值:hf1.Set('sBH', ASPxGridView1.GetRowKey(ASPxGridView1.GetFocusedRowIndex())); //给隐藏字段赋值为ASPxGridView1当前被选中行的bh值
后台取值:ASPxHiddenField1.Get("sBH");
前台取值:hf1.Get('sBH')
13.ASPxPopupControl自定义约会表单
设置前台名称:ClientInstanceName="ASPxPopupControl1"; 前台显示ASPxPopupControl自定义表单:ASPxPopupControl1.Show(); 前台隐藏ASPxPopupControl自定义表单:ASPxPopupControl1.Hid();