views:

31

answers:

1

I asked a question similarly, but the outcome was pretty messy and I was having difficulties populating so I'm trying to go at from a different angle: http://stackoverflow.com/questions/2060835/question-concerning-asplistview-and-multiple-dynamically-created-controls

I have a table which stores steps in a process. Some companies only have 6 steps while others have 15, so I created a table with 15 different slots for steps. What I would like to do is set up a control that displays each step in its own row with a label next to it saying "Step '#'", and not in an adjacent column. I'd also like for it to not display any blank rows. If they are entering the step instructions, I would want for them to have to press a button that would add a row so that they aren't just given 15 empty text boxes to fill in.

What would be the best control to do this in, and how would I get started in setting it up?

+2  A: 

You are putting data in the field names in the table, which makes your task more complicated. Instead of storing the steps in columns, like this:

CompanyId  Step1  Step2  Step3  Step4  Step5  Step 6  Step7 ...
1          alpha  beta   gamma
2          one    two    three  four   five

You should store the steps as rows, so that you get the step number as data in a field:

CompanyId  StepNumber  Step
1          1           alpha
1          2           beta
1          3           gamma
2          1           one
2          2           two
2          3           three
2          4           four
2          5           five

This way you don't get any unused fields, and the data model doesn't pose any limitation on the number of steps. Also, you can easily get the steps as a collection instead of having to get each one separately and add to a collection.

Something like:

var steps =
  from s in CompanySteps
  where s.CompanyId = 2
  orderby s.StepNumber
  select new { s.StepNumber, s.Step };

Then you have many different options to display the steps, like using the collection as data source in a Repeater, or loop through the items and just create HTML code for them and put in a Literal control.

Guffa