Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display Images in a Grid like manner 1

Status
Not open for further replies.

hondaman2003

Programmer
Mar 3, 2008
202
0
0
US
I have a website that I would like to display images in rows and columns just like in a table. For example, if I have 9 images, I would like to display them in a 3 columns, 3 rows. This information is going to come from a database so I could have any number of images that need to be displayed but I need to stick to 3 columns and as many rows as needed.

I am trying to dynamically generate this using the asp table control. Here is the code I am using to play with this control and yet, I am only getting a blank page.

HTML

Code:
<asp:Table ID="tblHTMLImageList" runat="server">
</asp:Table>

C#

Code:
protected void Page_Load(object sender, EventArgs e)
{
    TableRow tRow = new TableRow();
    TableCell tCell = new TableCell();
        

    tCell.Text = "Row 1, Column 1";
    tCell.ID = "Cell1";
    tRow.Cells.Add(tCell);
    tCell.Text = "Row 1, Column 2";
    tCell.ID = "Cell2";
    tRow.Cells.Add(tCell);
    tblHTMLImageList.Rows.Add(tRow);

    tRow.Cells.Clear();
        
    tCell.Text = "Row 2, Column 1";
    tCell.ID = "Cell3";
    tRow.Cells.Add(tCell);
    tCell.Text = "Row 2, Column 2";
    tCell.ID = "Cell4";
    tRow.Cells.Add(tCell);

    tblHTMLImageList.Rows.Add(tRow);
}
 
I tried your example and I guess you can't reuse the cell and row as you expected. I tried the code below and it does work:
Code:
        TableRow tRow = new TableRow();
        TableCell tCell = new TableCell();


        tCell.Text = "Row 1, Column 1";
        tCell.ID = "Cell1";
        tRow.Cells.Add(tCell);

        tCell = new TableCell();
        tCell.Text = "Row 1, Column 2";
        tCell.ID = "Cell2";
        tRow.Cells.Add(tCell);
        tblHTMLImageList.Rows.Add(tRow);

        //tRow.Cells.Clear();
        tRow = new TableRow();

        tCell = new TableCell();
        tCell.Text = "Row 2, Column 1";
        tCell.ID = "Cell3";
        tRow.Cells.Add(tCell);

        tCell = new TableCell();
        tCell.Text = "Row 2, Column 2";
        tCell.ID = "Cell4";
        tRow.Cells.Add(tCell);

        tblHTMLImageList.Rows.Add(tRow);
 
I duplicated what you have just demonstrated and it also works for me. Thank you for the information. On a side note, I think it's a little weird that you cannot reuse the object like you can most if not all other objects by just giving a new value.
 
I would think once you add the cell to the row you could reuse it. But I have no idea what is going on behind the scenes when you add the cell or row. Perhaps they are not actually "released" for reuse.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top