分享

GridView 特性总结

 mefly 2008-01-11

DataGird
GridView调查:
1、前台文件变化:
***.aspx.designer.cs
.DataGrid .GridView
DataGrid GridView
***.aspx
ASP:DATAGRID asp:GridView
ITEMSTYLE RowStyle DATAGRID之后<COLUMNS>之前
ASP:BOUNDCOLUMN asp:BoundField
ASP:TEMPLATECOLUMN asp:TemplateField
<PAGERSTYLE POSITION="TopAndBottom" MODE="NumericPages"> <PagerSettings Position="TopAndBottom" />
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  得到一行
<ASP:BUTTON ID="btn更新"  CommandArgument="<%# Container.DataItemIndex%>" 页面
 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 属性即可。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多