GridView 特性总结

来源:百度文库 编辑:神马文学网 时间:2024/04/30 02:50:22
DataGird转GridView调查:
1、前台文件变化:
***.aspx.designer.cs
.DataGrid .GridView
DataGrid GridView
***.aspx
ASP:DATAGRID asp:GridView
ITEMSTYLE RowStyle DATAGRID之后之前
ASP:BOUNDCOLUMN asp:BoundField
ASP:TEMPLATECOLUMN asp:TemplateField

MODE="NumericPages" Mode="Numeric"
SortExpression=‘<%#getSortExp("オーダ番号")%>‘
2、后台文件变化:
***.cs
ItemCommand RowCommand
DataGridCommandEventHandler GridViewCommandEventHandler
DataGridCommandEventArgs GridViewCommandEventArgs
PageIndexChanged PageIndexChanging 不通用
DataGridPageChangedEventHandler GridViewPageEventHandler
DataGridPageChangedEventArgs GridViewPageEventArgs
SortCommand Sorting
DataGridSortingEventHandler GridViewSortEventHandler
DataGridSortingEventArgs GridViewSortEventArgs
ItemDataBound RowDataBound
DataGridItemEventHandler GridViewRowEventHandler
DataGridItemEventArgs GridViewRowEventArgs e.row
CurrentPageIndex PageIndex 不通用
3、对于包含e.item的值的修改:
前台:
(1) 控件中添加属性:CommandArgument="<%# Bind(‘DataField‘) %>"   (绑定字段) GridViewCommandEventHandler
(2) CommandArgument=‘<%# Container.DataItemIndex%>‘   (绑定行号)
后台:
(1) e.Item.Cells[0].Text e.CommandArgument.ToString()
(2) e.Item.Cells[0].Text this.dgPJList.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].Text
修改: e.Item this.dgPJList.Rows[Convert.ToInt32(e.CommandArgument) % dgPJList.PafeSize]
4、追加RowDataBound方法
例: private void dgPJList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowType == DataControlRowType.DataRow) || (e.Row.RowType == DataControlRowType.Header)
|| (e.Row.RowType == DataControlRowType.Footer))
{
e.Row.Cells[0].Visible = false;
}
}
5、枚举类型 ListItemType 改为 DataControlRowType 和 DataControlRowState
ListItemType 枚举表示可以包含在列表控件中的不同项,例如 DataGrid、DataList 和 Repeater 控件。典型的列表控件由包含此枚举所表示的元素的单元格组成。
成员名称 说明
AlternatingItem  交替(从零开始的偶数索引)单元格中的项。它是数据绑定的。
EditItem         列表控件中当前处于编辑模式的项。它是数据绑定的。
Item             列表控件中的项。它是数据绑定的。
SelectedItem     列表控件中的选定项。它是数据绑定的。
Separator        列表控件中项之间的分隔符。它不是数据绑定的。
Footer           列表控件的页脚。它不是数据绑定的。
Header           列表控件的页眉。它不是数据绑定的。
Pager            页导航,显示定位到与 DataGrid 控件关联的不同页的控件。它不是数据绑定的。
DataControlRowType 枚举 指定数据控件中行的功能:
成员名称 说明
DataRow         数据控件的数据行。只有 DataRow 行能绑定数据。
EmptyDataRow    显示页按钮或页导航控件的行。页导航行不能绑定数据。
Footer          数据控件的脚注行。脚注行不能绑定数据。
Header          数据控件的标题行。标题行不能绑定数据。
Pager           显示页按钮或页导航控件的行。页导航行不能绑定数据。
Separator       行分隔符。行分隔符不能绑定数据。
DataControlRowState枚举 指定数据控件中行的状态:
成员名称 说明
Alternate   指示该数据控件行是交替行。
(Alternate状态在任何时候都可以与其他状态组合,例如与 Normal、Edit 或 Insert 组合。这些行可能会受到数据控件的 AlternateRowStyle 属性影响(若已设置)。)
Edit        指示该行处于编辑状态,这通常是单击行的“编辑”按钮的结果。通常,Edit 和 Insert 状态互相排斥。
Insert      指示该行是新行,这通常是单击“插入”按钮添加新行的结果。通常,Insert 和 Edit 状态互相排斥。
Normal      指示该数据控件行处于正常状态。Normal 状态与其他所有状态互相排斥。
Selected    指示该行已被用户选定。
此枚举有一个 FlagsAttribute 属性,允许其成员值按位组合。在GridView或DetailsView 中,行的状态可以是一个 DataControlRowState 值或值的组合,因此使用按位运算来确定该行的状态是否包括一个 DataControlRowState 值而非一个等效测试。
GridViewCommandEventArgs  得到一行
TextBox tb1 = (TextBox)gvr.Cells[1].Controls[0];
tb1.Text 普通字段(文本框)
skillText = (WebManV3.Web.userControls.UcText)row.Cells[2].FindControl("スキルR"); 用户控件
string tb1 = gvr.Cells[0].Text; 主键(readonly)
datagrid 改 gridview
ASP:BOUNDCOLUMN   >>   ASP:BoundField
ASP:TEMPLATECOLUMN   >>  ASP:TemplateField
常见错误
The base class includes the field ‘dg実務経験‘, but its type (System.Web.UI.WebControls.DataGrid) is not compatible with the type of control (System.Web.UI.WebControls.GridView).
GridView 使用经验点滴:获取 TemplateField 中的控件引用     2006-08-17 01:00:42
大 中 小
如果 GridView 中使用了 TemplateField 列,要想在运行时取得该列中某个控件的引用,需要在 GridView 的 RowCreated 事件中进行。
RowCreated 事件的 GridViewRowEventArgs 参数有一个属性 Row,这就是当前行的引用,通过 Row 的 FindControl 方法,传递你要获取引用的控件的 ID 就可以返回该控件的引用了。
记得先判断一下这个 Row 的类型:e.Row.RowType ==  DataControlRowType.DataRow
另外,点击 TemplateField 列中的按钮时,触发的是 GridView 的 RowCommand 事件。首先你要设置按钮的 CommandName,这样在 RowCommand 中就能知道点击的是哪个按钮;另外你需要知道被点击的按钮是那一行的按钮,就稍微麻烦一点。可以通过按钮的 CommandArgument 来设置,但 GridView 不会自动为你设置,方法就是在 GridView 的 RowCreated 事件中获取当前行的行号赋值给按钮的 CommandArgument 属性即可。