I have an application page where there are 52 consecutively named text boxes to allow the entry and display of weekly demand numbers for a year. My question is is there a way to "parameterize" a control (text box in this case) name so that I can loop through them instead of having to list out all 52?
For instance, I am currently verbosely listing them all out like this:
IEnumerable<DemandPattern> demandPattern = db.DemandPatterns.Where(x => x.DemandPatternID == demandPatternID);
txtBox1.Text = demandPattern.Where(x => x.Week == 1).Select(x => x.Demand).FirstOrDefault().ToString();
txtBox2.Text = demandPattern.Where(x => x.Week == 2).Select(x => x.Demand).FirstOrDefault().ToString();
...
txtBox51.Text = demandPattern.Where(x => x.Week == 51).Select(x => x.Demand).FirstOrDefault().ToString();
txtBox52.Text = demandPattern.Where(x => x.Week == 52).Select(x => x.Demand).FirstOrDefault().ToString();
I know I could wrap this in a for loop and replace the week # with the i variable, but how to deal with the textbox name...
for (int i = 1; i <= 52; i++)
{
txtBoxi.Text = demandPattern.Where(x => x.Week == i).Select(x => x.Demand).FirstOrDefault().ToString();
}
I know there's got to be a better way to do this... This is an asp.net web app.