Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. My dynamic table will not display...

My dynamic table will not display...

Scheduled Pinned Locked Moved C#
csharpc++question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chip Long
    wrote on last edited by
    #1

    I have a table that is being dynamically generated based on selected fields from my form. However, after I have modified the table, I can't get it to display on the web page. What am I doing wrong or what else do I need to do to get the page to display correctly? ASP place holder:

    (I have tried EnableViewState="false" too.) C# code:

    protected void MakeBrowserOSTable(DataTable dtContents)
    {
    int numRows = dtContents.Rows.Count;
    int numCells = dtContents.Columns.Count;

    Table newTable = new Table(); // The table can totally change depending on the
                                  // selection - so I want to rebuild it each time.
    
    if ((numCells <= 0) || (numRows <= 0))
    {
        TableRow row = new TableRow();
        TableCell cell = new TableCell();
        cell.Controls.Add(new LiteralControl("Please choose a platform"));
        row.Cells.Add(cell);
        newTable.Rows.Add(row);
    }
    else
    {
        foreach (DataRow r in dtContents.Rows)
        {
            TableRow row = new TableRow();
    
            for (int c = 0; c < numCells; c++)
            {
                TableCell cell = new TableCell();
    
                if (c == 0)
                {
                    Label lbl = new Label();
                    lbl.Text = (string)r\[c\];
                    lbl.Text = lbl.Text.Trim();
                    cell.Controls.Add(lbl);
                }
                else
                {
                    //add other controls here
                }
                row.Cells.Add(cell);
            }
            newTable.Rows.Add(row);
        }
    }
    tblBrowserOSTable = newTable;
    

    }

    T 1 Reply Last reply
    0
    • C Chip Long

      I have a table that is being dynamically generated based on selected fields from my form. However, after I have modified the table, I can't get it to display on the web page. What am I doing wrong or what else do I need to do to get the page to display correctly? ASP place holder:

      (I have tried EnableViewState="false" too.) C# code:

      protected void MakeBrowserOSTable(DataTable dtContents)
      {
      int numRows = dtContents.Rows.Count;
      int numCells = dtContents.Columns.Count;

      Table newTable = new Table(); // The table can totally change depending on the
                                    // selection - so I want to rebuild it each time.
      
      if ((numCells <= 0) || (numRows <= 0))
      {
          TableRow row = new TableRow();
          TableCell cell = new TableCell();
          cell.Controls.Add(new LiteralControl("Please choose a platform"));
          row.Cells.Add(cell);
          newTable.Rows.Add(row);
      }
      else
      {
          foreach (DataRow r in dtContents.Rows)
          {
              TableRow row = new TableRow();
      
              for (int c = 0; c < numCells; c++)
              {
                  TableCell cell = new TableCell();
      
                  if (c == 0)
                  {
                      Label lbl = new Label();
                      lbl.Text = (string)r\[c\];
                      lbl.Text = lbl.Text.Trim();
                      cell.Controls.Add(lbl);
                  }
                  else
                  {
                      //add other controls here
                  }
                  row.Cells.Add(cell);
              }
              newTable.Rows.Add(row);
          }
      }
      tblBrowserOSTable = newTable;
      

      }

      T Offline
      T Offline
      TylerBrinks
      wrote on last edited by
      #2

      What happens if you enable viewstate? let's start there.

      C 1 Reply Last reply
      0
      • T TylerBrinks

        What happens if you enable viewstate? let's start there.

        C Offline
        C Offline
        Chip Long
        wrote on last edited by
        #3

        I don't see any difference between the EnableViewState being set to "true" or "false". From reading the MSDN site, I think this needs to be "false" to update the view dynamically.

        C 1 Reply Last reply
        0
        • C Chip Long

          I don't see any difference between the EnableViewState being set to "true" or "false". From reading the MSDN site, I think this needs to be "false" to update the view dynamically.

          C Offline
          C Offline
          Chip Long
          wrote on last edited by
          #4

          I finally figured this out. I wasn't approaching the problem correctly. I had to change my ASP code to be an ASP:Placeholder:

          Then at the end of my code, instead of assigning the new table to the existing table (which is now gone), I replaced the placeholder control with the new table:

          tblBrowserOSTable.Controls.Clear();
          tblBrowserOSTable.Controls.Add(newTable);

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups