復制代碼 代碼如下:
1、RowCommad
//獲得索引
int index = ((GridViewRow)(((Button)(e.CommandSource)).Parent.Parent)).RowIndex;
2、RowEditing等
//獲得索引
int index = e.NewEditIndex;
//獲取當前GridViewRow對象
GridViewRow editGridViewRow = autoGridView.Rows[girdviewEditIndex];
//獲取內容方法一 row中有控件Label
Label girdviewTitleLabel = editGridViewRow.Cells[0].FindControl("titleLabel") as Label;
string gridViewContent = girdviewTitleLabel.Text;
//獲取內容方法二 row中有無控件Label
//string gridViewContent = editGridViewRow.Cells[0].Text;
3、RowDeleting等
//獲得索引
int index=e.RowIndex ;
//獲取當前GridViewRow對象
GridViewRow gvr=autoGridView.Rows[index];
//取得當前行第二個單元格中的文字
string str = gvr.Cells[1].Text;