0

I am writing a program that asks the user how many fields(tests, assignments, and practicals).

I so far have a hardcoded table with 5(maximum) fields for tests, assignments, and practicals which will become visible once I have the user selection.

e.g if the user selects 3 tests, only txtTest1, 2 and 3 will become visible.

What I actually want to do is have a dynamic page which creates the table according to the user selection.

The problem I am facing is creating this table with input fields I can pull from in the code of the webpage.

Could anyone help, please?

I would like to know if this is possible and how before i code further.

This is what I have so far:

The webpage before user input:

beforeUserInput

After user selection and button click:

After user selection

In the code, I would like to have something like this:

Test test1 = new Test();
test1.Weighting = txtTest1W.Text;
test1.Date = txtTest1D.Text;

MAH.AddTest(test1);

Any help would be appreciated, thank you.

Cleaven
  • 974
  • 2
  • 9
  • 30
  • You could use a [Repeater control](https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater(v=vs.110).aspx) and declare an [ItemTemplate](https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemtemplate(v=vs.110).aspx) - then simply populate a collection of (blank) items and bind it to the Repeater. – Filburt Apr 04 '18 at 17:24
  • @Filburt Sorry for the delayed response. How would I be able to create blank items and access them on the code side, if you follow what I'm saying – Cleaven Apr 07 '18 at 12:08
  • If you did not already find out from Cory's answer - this is the core of asp.net: handle collections of objects/data code-side and bind them to page controls. Check any of the samples for the controls Cory mentioned and you will see how it is meant to work. – Filburt Apr 07 '18 at 14:39
  • @Filburt Thank you for your help, much appreciated. – Cleaven Apr 09 '18 at 21:55

1 Answers1

2

I would suggest looking into using a DataList. Also, take a look at this article on Deciding When to Use the DataGrid, DataList or Repeater. Finally, You may want to look at some of the answers here: How to create a three column table in ASP.Net Repeater.

Cory
  • 783
  • 5
  • 12