Gridview 用法大全三
在VS2005提供的GridView中我们可以直接添加一个CommandField删除列:<asp:CommandField ShowDeleteButton="True" />,然后在GridView的OnRowDeleting事件中完成删除。但一般情况下我们在做这种删除操作时都需要先让用户确认一下,然后后再删除记录,以避免误操作引起的误删除。
那我们可以通过下面方法给GridView删除前加上一个确认对话框。
首先,在GridView的属性对框话框中点击“Columns”进入它的"字段"设计器;或者在设计窗口直接点击GridView控件右上角的那个小箭头,点击"编辑列",进入"字段"设计器。
接着在"字段"设计器中的左下方"选定的字段"框中,选择以前已加上的那个CommandField“删除”列,这时在右边它的属性列表下会看到一个"将此它段转换为 TemplateFied"的项,点击将它转换为TemplateFied列。
然后退出"字段"设计器,切换到源码视图你会发现该列已由原来的:
<asp:CommandField ShowDeleteButton="True" />
变为了:







最后在<asp:LinkButton>中加入:OnClientClick="return confirm('您确认删除该记录吗?');"
这样点击删除时就会先在客户端弹出“您确认删除该记录吗?”对话框,点击"确定",则进行删除;点击"取消",则不删除.
而原来在onRowDeleting事件中写的代码完全不用改变。鼠标在GridView上移动时变换颜色









RowCreated:开被创建时发生
e.Row.RowType == DataControlRowType.DataRow 判断是否是数据行
DataControlRowType的枚举有:
DataRow数据行
EmptyDataRow
Footer
Header
Pager
Separator
如果对单元格进行变换。





不足。前端页面代码过多。站带宽。
在GridView的第一列使用CheckBox控制每一行数据,是经常使用的,这里面我要记录的是全选、全消、选中行的底色更改,还有就是在提交数据的时候,取选中的行的编号等功能