ASPxGridview使用总结

ASPXGridView:数据展示、绑定与高级功能详解
本文详细介绍了ASPXGridView的外观定制、数据绑定、过滤、删除、更新操作,以及排序、分页、自定义列、导出和常见问题的解决方案。涵盖了关键功能实现和优化技巧。

一。ASPXGridView外观显示
属性:
Caption----列的标题(
KeyFieldName----数据库字段
SEOFriendly 是否启用搜索引擎优化
Summary 指定分页汇总信息的格式

Setting节点的ShowFilterRow=True设置快速查找功能

SettingsBehavior.AllowFocusedRow=true 高亮选中的行,即选中行变色
SettingsBehavior.AllDragDrop=false禁止拖动标题列头
SettingsBehavior.AllowSort实现列头点击后是否可以排序
SettingsPager.ShowEmptyDataRows=True;当数据行为空时,显示空行
SettingsPager.PageSize 每页显示的记录总数
AllButton.Text “全部数据显示”按钮的文本
AllButton.Visible 是否显示“全部数据显示”按钮
FirstPageBuotton/LastPageButton/NextPageButton/PrevPageButton/ 对应首页、末页、下页、上页,设置同上。
NumericButtonCount 最小值为1,控制页码显示个数
protected void ASPxGridView1_PageIndexChanged(object sender, EventArgs e)
{
databind();//只需重新绑定数据即可实现上下翻页
}
新建的列默认是GridViewDataTextColumn类型,选择工具栏的Change To变更列的类型,可以改变新增或修改时的编辑方式。
设置日期类型显示格式,在“行为”PropertiesDateEdit–DisplayFormatString–例如:{0:yyyy年MM月}

当选择了show Group Panel时,FocusedRowChanged事件,重绑定数据,使用时先选中行,再查看
protected void ASPxGridView1_FocusedRowChanged(object sender, EventArgs e)
{
getdata();
}

禁止某一列进行编辑,该列的行为-EditFormSettings-Visible=False

代码中隐藏编辑列的增加,删除,更新按钮
(ASPxGridView1.Columns[编辑列] as GridViewCommandColumn).NewButton .Visible= true;
(ASPxGridView1.Columns[编辑列] as GridViewCommandColumn).DeleteButton.Visible = true;
(ASPxGridView1.Columns[8] as GridViewCommandColumn).UpdateButton .Visible= true;

每行都有一个CHECKBOX,可以动态选择,只需要这样即可

<dx:GridViewCommandColumnShowSelectCheckbox ="true"VisibleIndex=“8”></dx:GridViewCommandColumn>
…其它列

二。ASPXGridView绑定数据
ASPxGridView1.KeyFieldName = “ID”;//指定主键。直接更新数据和子表绑定 需要用到

ASPxGridView1.DataSource = dt.defaultView;//指定Grid的数据
ASPxGridView1.DataBind(); //执行绑定
注意,如果查询结果字段有别名,编辑该字段时,UnboundType应设为Object
三。ASPXGridView查找
过滤数据,查找数据
方式一、展开列标题旁边的过滤清单过滤数据(类似Excel的过滤方式)grid.Settings.ShowHeaderFilterButton = true;过滤清单列出了该列出现的所有数据。还可以自定义过滤清单的内容,用法参阅:http://demos.devexpress.com/ASPxGridViewDemos/Filtering/HeaderFilter.aspx

方式二、在列头显示字段过滤条件输入框 grid.Settings.ShowFilterRow = true; 显示条件判断方式下拉列表grid.Settings.ShowFilterRowMenu = true;

四删除数据
protected void ASPxGridView1_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
{
e.Cancel = true;//否则,只有刷新页面才能看到删除后的结果
int id =Convert.ToInt32( e.Keys[0]);//获取ID<

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值