新手在這裏所以不知道什麼是潛在的性能問題,在這裏,什麼是最好的做法。訪問的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;
}
}