I've written this set of code and feel that it's pretty poor in quality. As you can see, in each of the four case statements I'm ending up repeating an awful lot of the same code except for a few variations in each case. Items that vary; session names, gridnames and the ManagerContext group name. Can anyone take this mess of code and show me a better way of doing this?
private void LoadGroup(string option)
{
switch (option.ToUpper())
{
case "ALPHA":
VList<T> alphaList = FetchInformation(ManagerContext.Current.Group1);
if (Session["alphaGroup"] != null)
{
List<T> tempList = (List<T>)Session["alphaGroup"];
alphaList.AddRange(tempList);
}
uxAlphaGrid.DataSource = alphaList;
uxAlphaGrid.DataBind();
break;
case "BRAVO":
VList<T> bravoList = FetchInformation(ManagerContext.Current.Group2);
if (Session["bravoGroup"] != null)
{
List<T> tempList = (List<T>)Session["bravoGroup"];
bravoList.AddRange(tempList);
}
uxBravoGrid.DataSource = bravoList;
uxBravoGrid.DataBind();
break;
case "CHARLIE":
VList<T> charlieList = FetchInformation(ManagerContext.Current.Group3);
if (Session["charlieGroup"] != null)
{
List<T> tempList = (List<T>)Session["charlieGroup"];
charlieList.AddRange(tempList);
}
uxCharlieGrid.DataSource = charlieList;
uxCharlieGrid.DataBind();
break;
case "DELTA":
VList<T> deltaList = FetchInformation(ManagerContext.Current.Group4);
if (Session["deltaGroup"] != null)
{
List<T> tempList = (List<T>)Session["deltaGroup"];
deltaList.AddRange(tempList);
}
uxDeltaGrid.DataSource = deltaList;
uxDeltaGrid.DataBind();
break;
default:
break;
}
}