2010-02-09 51 views

回答

2

您可以在GridView.Columns中找到一列,然後使用其索引查找所需的單元格。事情就像這個例子:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    var myColumn = GridView1.Columns.Cast<DataControlField>().First(c => c.HeaderText == "MyColumn"); 
    var row = GridView1.Rows[int.Parse(e.CommandArgument.ToString())]; 
    var cell = row.Cells[GridView1.Columns.IndexOf(myColumn)]; 
} 
0

這裏是VB.NET:

Dim id As Integer = GridView.Columns.IndexOf(GridView.Columns.Cast(Of DataControlField)().First(Function(c) c.HeaderText = "Column Header")) 
相關問題