I am building a dynamic table with back end code using Visual Studio and C#. The problem that I have is that I either get each record in an individual row or all records in one row. I would like to use say a for statement to put say 3 to 4 items in a row, then start a new row. I have tried changing the code multiple times, but still don't get it to appear they way I want it to look.
This puts each image in an individual row.
while (theReader.Read())
{
dieCutRow = new TableRow();
string dieName = theReader["DieName"].ToString();
string dieImage = theReader["Image"].ToString();
string dieDirectory = theReader["DieType"].ToString();
string dieURL = "images/" + dieDirectory + "/" + dieImage;
dieCutCell = new TableCell();
dieCutCell.Style.Add("width", "100px");
dieCutCell.CssClass += " cartPaddingLeft";
dieCutCell.Text = "<img src='images/" + dieDirectory + "/" + dieImage + "' width='100'/>";
dieCutRow.Cells.Add(dieCutCell);
dieCutCell = new TableCell();
dieCutCell.Style.Add("width", "100px");
dieCutCell.CssClass += " cartPaddingLeft";
dieCutCell.Text = "" + theReader["DieName"].ToString() + " ";
dieCutRow.Cells.Add(dieCutCell);
tblDieCuts.Rows.Add(dieCutRow);
}
If I take the
dieCutRow = new TableRow();
and
tblDieCuts.Rows.Add(dieCutRow);
move them outside the while loop, then I get a single row with all of my data in it.
What I have tried:
I have tried adding a for loop, etc. I thought about a SortedList. A gridview basically gives me what I currently have with the existing code.