GridView 常用用法

DevExpress-GridControl控件-GridView使用 GridControl在不同版本(目前使用14.1.8)提供了多种不同的视图,它不仅比DataGridView强大,而且在数据加载性能各方面也有了很大的提升。 在此对之前的研究做一份整理记录,以备后用。 阅读详情

 

这篇日志有点长,收集了一些网上的资源,同志们可以按需要选择来看。目录是这样的:
这个颜色的是笨猫的注释

·GridView的常用用法总结
·如何获取 GridView 编辑状态下单元格里的值


先叙述一下我碰到问题的:

道路表road:roadid,roadname,startjunid,endjunid
路口表junction:junid,junname
startjunid,endjunid存的是int型编号,显示时要显示junname路口名字,于是做了一个视图view_road_junction
现在用一GridView和view_road_junction绑定显示数据。同时要求能对数据进行修改,变动反应到road表中。

我的做法是:
因为是视图,不能直接用GridView自动生成的编辑功能(已经用不同方法尝试过,不行,偷懒不成功),所以写了一个OnRowUpdating事件,GridView1_RowUpdating(),在此函数中获取GridView在编辑状态下的单元格的值,对road表进行更新操作。点击页面上的"编辑"按钮的时候触发该事件。

------------------
GridView的常用用法总结
------------------
GridView七种类型字段

Field字段类型

说明

BoundField(数据绑定字段)

将Data Source数据源的字段数据以文本方式显示

ButtonField(按钮字段)

在数据绑定控件中显示命令按钮。根据控件的不同,它可让您显示具有自定义按钮控件(例如【添加】或【移除】按钮)的数据行或数据列,按下时会引发RowCommand事件

CommandField(命令字段)

显示含有命令的Button按钮,包括了Select、Edit、Update、Delete命令按钮(DetailsView的CommandField才支持Insert命令)

CheckBoxField(CheckBox字段)

显示为CheckBox类型,通常用于布尔值True/False的显示

HyperLinkField(超链接字段)

将Data Source数据源字段数据显示成HyperLink超级链接,并可指定另外的NavigateUrl超链接

ImageField(图像字段)

在数据绑定控件中显示图像字段

TemplateField(模板字段)

显示用户自定义的模板内容

 

GridView四种样式

通过ControlStyle可设置BoundField字段服务器子控件的样式。

通过FooterStyle可设置BoundField字段之页尾的样式。

通过HeaderStyle可设置BoundField字段之页首的样式。

通过ItemStyle可设置BoundField字段中数据项的样式。

 

格式化字符串

格式代号

说  明

原始格式

格式指令

运行结果

{0:C}

显示货币符号格式

2005.5

{0:C2}

NT$2,005.50

{0:D}

显示十进制数格式(限用于整数)

128

{0:D}

128

{0:E}

显示科学符号格式

2005.5

{0:E2}

2.01E+003

{0:F}

显示固定小数字数格式

2005.5

{0:F4}

2005.5000

{0:G}

显示一般格式

2005.5

{0:G}

2005.5

{0:N}

显示有逗号固定小数字数格式

2005.5

{0:N3}

2,005.500

{0:P}

显示百分比格式

0.25

{0:P}

25.00%

{0:X}

显示十六进制数格式(限用于整数)

128

{0:X}

80

{0:#}

显示自定义的数字格式

2005.5

{0:00####.00}

002005.00

 

各种类型字段使用方法

BoundField :

HeaderText  列名(在网页中显示出来的)

HeaderImageUrl  列头的图片  

DataField  数据源字段名

NullDisplayText  当该字段的值为空时显示的值

ButtonField:

ButtonType  有Button?Image?Link三种

DataTextField  将数据源字段数据绑定到Button按钮的文本属性中

ImageUrl  当按钮形式为Image时,指定Image所在的Url

CommandName  单击ButtonField按钮时所要运行的命令名称

相关事件:

当ButtonField按钮字段被按下时,GridView控件会引发RowCommand事件,

若要判断引发命令事件之数据行的索引,请使用事件自变量的CommandArgument属性,会将该事件自变量传递至数据绑定控件的命令事件,ButtonField类会自动用适当的索引值填入CommandArgument属性。在事件响应函数中可以根据不同的CommandName来做不同的操作。

从事件中判断e.CommandName和对第几行进行的操作e.CommandArgument。

Example:

if (e.CommandName == "Select")

        {

            int index = Convert.ToInt32(e.CommandArgument);

        }

}

 

CommandField:

五种命令:Select、Edit、Update、Delete与Insert。显示及隐藏命令按钮您可以设置ShowDeleteButton、ShowEditButton、ShowInsertButton与ShowSelectButton这几个属性(True或False)。而设置不同命令按钮的文字标题可用的属性有SelectText、InsertText、UpdateText、DeleteText、CancelText、EditText、NewText。

若您将ButtonType属性设为ButtonType.Image,则可以设置按钮的图像Url属性,可供使用的有CancelImageUrl、 DeleteImageUrl、EditImageUrl、InsertText、NewImageUrl、SelectImageUrl、 UpdateImageUrl。

SelectedRowStyle 用于设置选中行的风格

相关事件:

RowEditing  

RowDeleting

RowUpdating

RowCancelingEdit

注意:RowEditing和RowUpdating的不同

Example:( 摘自:http://hi.baidu.com/70zz)

后台代码:

你可以使用sqlhelper,本文没用。代码如下:

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.SqlClient;

 

public partial class _Default : System.Web.UI.Page

{

 

//清清月儿http://blog.csdn.net/21aspnet

     SqlConnection sqlcon;

     SqlCommand sqlcom;

     string strCon = "Data Source=(local);Database=数据库名;Uid=帐号;Pwd=密码";
    
protected void Page_Load(object sender, EventArgs e)

     {

         if (!IsPostBack)

         {

             bind();

         }

     }

     protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)

     {

         GridView1.EditIndex = e.NewEditIndex;

         bind();

     }

 

//删除

     protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)

     {

         string sqlstr = "delete from 表 where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";

         sqlcon = new SqlConnection(strCon);

         sqlcom = new SqlCommand(sqlstr,sqlcon);

         sqlcon.Open();

         sqlcom.ExecuteNonQuery();

         sqlcon.Close();

         bind();

     }

 

//更新
//gridview的列、行都是从0开始编号的

//我在用“GridView1.DataKeys[e.RowIndex].Value.ToString()”老是报“索引超出范围“,不知原因。
//建议改用后文写的”如何获取 GridView 编辑状态下单元格里的值“的方法

    
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)

     {

         sqlcon = new SqlConnection(strCon);

         string sqlstr = "update 表 set 字段1='"

             + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',字段2='"

             + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',字段3='"

             + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "' where id='"

             + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";

         sqlcom=new SqlCommand(sqlstr,sqlcon);

         sqlcon.Open();

         sqlcom.ExecuteNonQuery();

         sqlcon.Close();

         GridView1.EditIndex = -1;

         bind();

     }

 

//取消

     protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)

     {

         GridView1.EditIndex = -1;

         bind();

     }

 

//绑定

     public void bind()

     {

         string sqlstr = "select * from 表";

         sqlcon = new SqlConnection(strCon);

         SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);

         DataSet myds = new DataSet();

         sqlcon.Open();

         myda.Fill(myds, "表");

         GridView1.DataSource = myds;

         GridView1.DataKeyNames = new string[] { "id" };//主键

         GridView1.DataBind();

         sqlcon.Close();


//若在页面配置了数据源SqlDataSource1,用下2行代码,不过在页面里不要加SqlDataSourceID=SqlDataSource1属性了
        //GridView1.DataSource = SqlDataSource1;
        //GridView1.DataBind();
    
}

}

 

前台主要代码:

<!--
    使用时曾碰到这样的问题:要激发OnRowUpdating="GridView1_RowUpdating"事件,必须先写了OnRowEditing="GridView1_RowEditing"事件,不然会报”激发了未处理的事件RowEditing‘“,现在还没搞清楚什么原因。。。
-->  
                          
... ...

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"

                         ForeColor="#333333" GridLines="None" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"

                         OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit">

                         <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />

                         <Columns>

                             <asp:BoundField DataField="身份证号码" HeaderText="用户ID" ReadOnly="True" />

                             <asp:BoundField DataField="姓名" HeaderText="用户姓名" />

                             <asp:BoundField DataField="员工性别" HeaderText="性别" />

                             <asp:BoundField DataField="家庭住址" HeaderText="家庭住址" />

                             <asp:CommandField HeaderText="选择" ShowSelectButton="True" />

                             <asp:CommandField HeaderText="编辑" ShowEditButton="True" />

                             <asp:CommandField HeaderText="删除" ShowDeleteButton="True" />

                         </Columns>

                         <RowStyle ForeColor="#000066" />

                         <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />

                         <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />

                         <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />

                     </asp:GridView>

 

CheckBoxField:

DataField     设置绑定至数据源的字段名称

Text     设置CheckBox右侧的说明文字

ReadOnly     在编辑模式时,设置ReadOnly属性可以防止被编辑

 

HyperLinkField

DataTextField    绑定数据源字段显示成超链接文字

DataNavigateUrlFields     将数据字段绑定到超链接字段Url属性

Target   如果设置为"_blank"表示在空白页中打开

 

ImageField

DataImageUrlField    设置绑定至ImageField对象ImageUrl属性的数据源字段名称

 

TemplateField

ItemTemplate    字段项目模板

AlternatingItemTemplate 字段交替项目模板,若设置这个字段后,奇数行会显示ItemTemplate,偶数行显示AlternatingItemTemplate

EditItemTemplate     编辑项目模板

 

其他常见用法

1 程序中动态设置表头名称

gv.Columns[0].HeaderText=”表头”;

2 修改时获取文本控件上的文本

string card=((TextBox)CellGrid.Rows[e.RowIndex].Cells[1].Controls[0]).Text;

获得其他类型的控件同理,将上面代码的控件类型做修改即可

3 在每一行绑定数据时,会发生RowDataBound事件,可在这里添加相应的事件响应函数

4 删除之前提示是否确定删除:

在RowDataBound事件中加入该代码

if (e.Row.RowType == DataControlRowType.DataRow)
{
((CheckBox)e.Row.FindControl("CheckBox1")).Attributes.Add("onclick","return confirm('XXX')");
}

5 AutoGenerateColumns  是否自动添加列,如果是的话意味着是通过程序代码来实现添加的

 

 

分页的实现

关键属性:

AllowPaging设置为"True"

PageSize设置每一行显示的行数

Mode 分页样式,包含这四种:NextPreviousFirstLast、NumericFirstLast、NextPrevious、Numeric(Numeric指显示数字;First、Last指最开始和最后一个;Next、Previous指上一个和下一个)

FirstPageImageUrl、LastPageImageUrl、NextPageImageUrl、PreviousPageImageUrl分别指对应的图片

PagerStyle 中HorizontalAlign、VerticalAlign、BorderStyle用于设置分页控制的样式

 

关键事件

OnPageIndexChanging分页事件

当发生该事件后,重新绑定数据源

Example:

ArticleList.PageIndex = e.NewPageIndex;

if (Session["SQLStr"] != null)

{

   string SQLStr = Session["SQLStr"].ToString();

   GirdViewRefresh(SQLStr);

}

 

典型使用步骤:

添加GridView控件,设置相关属性:

Columns中添加相应的数据行

RowStyle、AlternatingRowStyle设置数据行样式

分页设置AllowPaging="True";PageSize设置每页好显示的行数

SelectedRowStyle 设置选择行的样式

在CS文件添加相应的响应函数:

(1)Page_Load中绑定数据源:

ArticleList.DataSource = ds.Tables[0].DefaultView;

ArticleList.DataBind();

 

(2)OnPageIndexChanging中更新页索引,重新绑定数据源

ArticleList.PageIndex = e.NewPageIndex;

if (Session["SQLStr"] != null)

{

     string SQLStr = Session["SQLStr"].ToString();

     GirdViewRefresh(SQLStr);

}

 

(3)RowCommand加入事件响应

if (e.CommandName == "Select")

        {

            int index = Convert.ToInt32(e.CommandArgument);

        }

}

----------------------
如何获取 GridView 编辑状态下单元格里的值
----------------------
还在使用这样的代码吗?

var txtName = grid1.Rows[e.RowIndex].Cells[0].FindControl("txtName") as TextBox;
if (txtName != null)
{
    
// 读取值
    
// 
}


其实这些工作(在单元格中查找控件,并尝试获取其中的值)已经被封装了。现在,只要调用 ExtractValuesFromCell 方法即可。
而该方法也被很多种列类型所支持:
DataControlField, BoundField, AutoGeneratedField, CheckBoxField, ImageField, TemplateField, DynamicField

你可以在 GridView 的 RowUpdating, RowDeleting 等事件中使用它。利用该方法,可以将值提取到所需的字典里去,然后再从字典中读取。这些字典包括:e.Keys, e.NewValues, e.OldValues 等。
一小段例子代码:

    // 更新
    protected void grid1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        var row 
= grid1.Rows[e.RowIndex];
        
// 提取 Id 字段的值
        grid1.Columns[0].ExtractValuesFromCell(
            e.Keys,
            row.Cells[
0] as DataControlFieldCell,
            DataControlRowState.Edit,
            
true /* include readonly */);

        
// 提取 Name 字段的值
        grid1.Columns[1].ExtractValuesFromCell(
            e.NewValues,
            row.Cells[
1] as DataControlFieldCell,
            DataControlRowState.Edit,
            
true /* include readonly */);

        var id 
= int.Parse(e.Keys["id"].ToString());
        var name 
= (string) e.NewValues["name"];

        
// 执行相关的数据库更新操作
        
// 
    }
这样,在大多数场合我们可以尽可能多的使用 BoundField,并且也能正确读取到其编辑时的值,省下自定义 TemplateField 的一堆代码了。

【GridView渐进全解】第一部分GridView基础 最早我是用asp 和php的,可是ASP.net来到后 我始终学不进去。恰好这时候ajax来了,学习了jQuery+bootstrap后,更是把asp.net扔到了脑后。今日,一个客户非让我帮他把他单位的老办公系统改造一下,实在难以推脱,只好先去看看。到现场发现,是他以前的一个员工用ASP.net自己写的。因此为了省事儿,我只好又把ASP.net拾起来了。这几年一直用c#写winform程序,因此再回过头来学ASP.net发现竟然很快就能上手。因为GridView最常用。 阅读详情

相关推荐

DevExpress GridControl GridView 新增行/删除行 AddNewRow /InitNewRow

针对DevExpress GridControl GridView 新增行AddNewRow() 很多人加了代码也无法实现添加行或者添加行后InitNewRow这个事件没有触发, 其中主要原因见附件实例代码!

Devexpress GridView使用gridView.AddNewRow()添加新行无效的解决方案

Devexpress GridView使用gridView.AddNewRow()添加新行无效的解决方案

lhycl的专栏 1742

[官方培训]07-UE材质基础 孙丹璐 Epic 笔记

勾选允许自定义深度写入再在模型上勾选然后可以通过Scene Texture节点拿到渲染的自定义深度信息,有了自定义深度信息就可以与当前渲染的像素深度进行对比,自定义深度信息存放的是最靠近我们的深度,如果当前像素离自定义深度比较远我们就不要这个像素。效果如下这种方案的缺点也很明显,因为这样看不到第二层的透明了,如果是两层的半透明的裙摆,这样就看不到第二层的裙摆了。对于半透明排序问题最根本能解决的还是光线追踪,ue5中又加入了OIT(基于像素的排序)。官方透明材质的理解和应用。

Tcohneyn的博客 1572

C#中gridView常用属性和技巧介绍

1.隐藏最上面的GroupPanel gridView1.OptionsView.ShowGroupPanel=false; 2.得到当前选定记录某字段的值 sValue=Table.Rows[gridView1.FocusedRowHandle][FieldName].ToString(); 3.数据只读 gridView1.OptionsBehavior.E...

spp1462的博客 1353

构建面向嵌入式Linux的ARM64交叉编译工具链:从sysroot配置到CMake实战

本文详细介绍了如何构建面向嵌入式Linux的ARM64交叉编译工具链,从sysroot配置到CMake实战。通过分步指导,帮助开发者解决架构不一致问题,提升编译效率,特别适用于树莓派等ARM64设备开发。文章涵盖sysroot机制、环境搭建、CMake配置及常见问题解决方案,是嵌入式开发的实用指南。

weixin_42537142的博客 206

Librepilot _64位window10环境下的搭建及一些坑的解决办法

  刚入IT行业的小菜鸟,在window上折腾了四天的librepilot地面控制站的搭建,想着这么辛苦不能白费了,看网上相关资料少得可怜,唯一一个详细教程还是在32位环境下,一大堆坑,所以把自己的经验写下来,供大家一起参考。 参考的原文是:https://www.cnblogs.com/jasonchan1202/p/7809937.html的博客,但是执行下来才发现这个博客对64位系统极其不...

weixin_41426339的博客 2732

gridView1新增行

/内置编辑器显示的模式。

wushijun5200的博客 787

Ultralytics 框架中 model.predict() 返回的 results 对象的详细解析

通过掌握 results 对象的使用方法,您可以快速实现模型部署、数据分析与可视化。

浩瀚之水的专栏 755

使用GridView实现一般操作

原文地址为: 【ASP.NET】GRIDVIEW控件的一般使用技巧 不得不说GridView控件的功能确实很强大,一个简简单单的控件就可以把数据管理的很美。在这两天做的任务中碰到的一些GridView控件中遇到的问题进行总结; ①:在GridView控件中随意显示数据库中的信息: GridView控件中有一个AutoGenerateColumns属性,它的作用就是控制GridView控件是否在运行的时候自动生成相关联的列,一般情况下把这个属性设置成为false。因为我们需要的是一个DIY的GridView控

zq9955的博客 388

OCR文字识别基础

ocr文字识别

m0_47405013的博客 1756

R语言层次聚类(hierarchical clustering):数据缩放、PCA聚类结果可视化、fpc包的clusterboot函数通过bootstrap重采样的方法评估hclust层次聚类的稳定性

R语言层次聚类(hierarchical clustering):数据缩放、PCA聚类结果可视化、fpc包的clusterboot函数通过bootstrap重采样的方法评估hclust层次聚类的稳定性

data+scenario+science+insight 841

获取GridView编辑状态下的新值

今天,在学习GridView的编辑操作时,遇到了一个问题,就是点击编辑按钮后,GirdView中出现了编辑框,修改完值提交后,GridView中的值还是原来的值。产生这个问题原因是由于页面进行了重新加载。具体地说就是在Page_Load中进行数据绑定的时候,并没有将数据绑定部分放到if(!IsPostBack)语句块中。另外,可以通过((TextBox)(GridView1.Rows[e.Ro

supersunshine的专栏 1214

C#实战OPC UA客户端:从连接到数据推送至KepServerEX的完整落地教程

核心标识:KepServerEX标签的NodeId是数据推送的关键,必须保证准确;连接稳定:实现断线重连逻辑是工业级应用的基础,避免因网络/服务器问题导致数据中断;效率优先:批量写入比单标签写入效率更高,适合高频率数据推送场景;类型匹配:数据类型必须与KepServerEX标签一致,否则写入失败;异常处理:每个核心操作都需加异常捕获,保证程序鲁棒性。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 218

GridView 常用用法 转贴!!

GridView 常用用法 这篇日志有点长,收集了一些网上的资源,同志们可以按需要选择来看。目录是这样的:·GridView的常用用法总结·如何获取 GridView 编辑状态下单元格里的值先叙述一下我碰到问题的:道路表road:roadid,roadname,startjunid,endjunid路口表junction:junid,junnamestartjunid,en...

weixin_30379531的博客 201

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Android常用控件之GridView与ExpandableListView的用法

概述1、GridView:与ListView相比,可以显示多列,xml布局时其属性numColumns可以设置显示的列数。 2、ExpandableListView:与ListView相比,可以让每一列单元都拥有子列表。内容GridView显示3列和多行的图片以及名称 布局<LinearLayout xmlns:android="http://schemas.android.com/apk/re

NiZhuanXingHeIT的博客 1230

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

asp.net gridview 常用用法

GridView无代码分页排序 GridView选中,编辑,取消,删除 GridView正反双向排序 GridView和下拉菜单DropDownList结合 GridView和CheckBox结合 鼠标移到GridView某一行时改变该行的背景色方法一 鼠标移到GridView某一行时改变该行的背景色方法二 GridView实现删除时弹出确认对话框 GridView实现自动编号

一曲肝肠断,天涯何处觅知音... 979

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

GridView添加事件监听和常用属性解析

1. 使用流程 graph LR 准备数据源-->新建适配器 新建适配器-->绑定数据源 绑定数据源-->加载适配器 2. 常用属性 android:columnWidth:每一列的宽度。 android:numColumns:指定显示的列数,若不指定该属性,则默认所有项排成1列。如果想让列数根据屏幕大小自适应,满了就自动换行,可以设置为"auto_fit"。 android:v...

weixin_30689307的博客 289

GridView控件使用及扩展

Gridview用法大总结http://www.cnblogs.com/huangjianhuakarl/archive/2009/02/03/1381710.html扩展GridView控件(索引) - 增加多个常用功能http://www.cnblogs.com/webabcd/archive/2007/02/04/639830.html 转载于:https://www.cnblogs.c...

weixin_34307464的博客 78

android studio 分页,Android Studio第十三期 - RecycleView所有用法

综合了一下hongyang和loader的RecycleView的所有场景用法:1.ListView列表分页用法核心代码:privatevoidcreateAdapter(){mAdapter=newRecycleAdapter1(this);LinearLayoutManagermLinearLayoutManager1=newLinearLayoutManager(this)...

weixin_34430580的博客 298

GridView 事件和用法

事件名称            说明    DataBinding 当服务器控件绑定到数据源时发生。 (从 Control 继承。)     DataBound 在服务器控件绑定到数据源后发生。 (从 BaseDataBoundControl 继承。)     Disposed 当从内存释放服务器控件时发生,这是请求 ASP.NET 页时服务器控件生存期的最后阶段。 (从 Control

wljhk2006的专栏 760

Flutter 常用组件详解:Text、Button、Image、ListView 和 GridView

Flutter 作为 Google 推出的跨平台 UI 框架,凭借其高效的渲染性能和丰富的组件库,已经成为移动应用开发的热门选择。本文将深入探讨 Flutter 中最常用的五个基础组件:Text、Button、Image、ListView 和 GridView,帮助开发者快速掌握 Flutter UI 开发的核心技能。

vvilkin的学习备忘 1356

Flutter的列表组件ListView、GridView和PageView

Scrolling Widget是一种基本组件,介绍一些基本的使用方法。 ListView 它具有四种构造方法: 默认构造函数ListView ListView.builder:适合具有大量列表项的ListView。 ListView.separated:可以配置分割线,适用于具有固定数量的列表项的ListView。 ListView.custom:提供自定义Widget的能力。 默认构造方式 MaterialApp( home: Scaffold(

weixin_42514162的博客 825

asp:GridView

                                                                                                                                                   

chenxue4076的专栏 291
上一篇: DOM解析java将文本也视为结点
下一篇: C#代码与javaScript函数的相互调用
kit_147
博客等级 码龄20年 25粉丝 8原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值