2012-07-26 66 views
0

新手在這裏所以不知道什麼是潛在的性能問題,在這裏,什麼是最好的做法。訪問的GridView行單元格是個好主意?

這是個好主意嗎?思考?

FROM THIS: (易當細胞碼是所有的地方和/或gridview的變化手工錯誤)

row.Cells[1].Visible = false; // CustomerId 
row.Cells[9].Visible = false; // OrderNumber 
row.Cells[10].Visible = false; // ProductId 
. . . 
int matchId = row.Cells[11].Text; 
. . . 

這樣: (更可讀和可管理的,只要確保枚舉是與gridview的同步)

row.Cells[Col.CustomerId.GetVal()].Visible = false;  
row.Cells[Col.OrderNumber.GetVal()].Visible = false; 
row.Cells[Col.ProductNumber.GetVal()].Visible = false; 
. . . 
int matchId = row.Cells[Col.CustomerName.GetVal()].Text; 
. . . 


public enum Col 
{ 
    MatchId = 1, 
. . . 
    ServiceCode = 9, 
    CustomerId = 10, 
    CustomerName = 11, 
. . . 

} 

public static class ColExt 
{ 
    static public int GetVal(this Col col) 
    { 
     return (int)col; 
    } 
} 

回答

1

在我看來,代碼是用枚舉更具可讀性。但是,重要的是你有枚舉(一個或多個)代碼生成。否則,如果你有很多列需​​要處理,你會犯很多錯誤。

1

及其如果在網格或在許多頁被用於大量的列的,如果正在使用相同的網格好主意。 ID將很容易從枚舉更改列值,它會反映所有網格....

相關問題