ASP Table Problem C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mylog
    New Member
    • Sep 2007
    • 20

    ASP Table Problem C#

    hi,
    I have a problem regarding the retrieval of data from a table.
    Here's is what I am doing.
    I have a created a table and from added the rows and columns and also data dynamically from the code in one of the function. Now I need to access that table and data on a button click, i.e. when a user clicks button I must be able to get the table information cell-wise. I have written the following code and when the user clicks the button all I get is the row count (i.e. no. of rows in the table are correct) but I cannot retrieve the cell information (or I have to say they are all empty). I have also tried to put the table into one Session but it also returned the same result. So is there any way this can be done. Does anyone has any idea about this.
    Help required urgently

    Looking forward to your support
    Thanks

    Inserting into table at button click

    Code:
    protected void btnAdvance_Click(object sender, EventArgs e)
        {
            Hashtable hsh = (Hashtable)Session["documentHash"];        
            Panel1.Visible = true;
            tbl = new Table();
            Panel1.Controls.Add(tbl);
            tbl.GridLines = GridLines.Both;
            int docListCount = AssocDocList.Items.Count;
            TableRow tr = new TableRow();
            TableCell tc1 = new TableCell();
            TableCell tc2 = new TableCell();
            TableCell tc3 = new TableCell();
            tc1.Controls.Add(new LiteralControl("Document Type ID"));
            tr.Cells.Add(tc1);
            tc2.Controls.Add(new LiteralControl("Document ID"));
            tr.Cells.Add(tc2);
            tc3.Controls.Add(new LiteralControl("Display Type"));
            tr.Cells.Add(tc3);
            tbl.Rows.Add(tr);
            for (int j = 0; j < docListCount; j++)
            {
                DropDownList ddl = new DropDownList();
                ddl.ID = "drop" + j;
                ddl.Items.Clear();
                ddl.Items.Add("PP");
                ddl.Items.Add("PD");
                ddl.Items.Add("DP");
                ddl.Items.Add("DD");
                TableRow r = new TableRow();            
                for (int i = 0; i < 3; i++)
                {
                    TableCell c = new TableCell();
                    if (i == 0)
                        c.Controls.Add(new LiteralControl(hsh[AssocDocList.Items[j].Text].ToString()));
                    else if (i == 1)
                        c.Controls.Add(new LiteralControl(AssocDocList.Items[j].Text));
                    else
                        c.Controls.Add(ddl);                    
    
                    r.Cells.Add(c);
                }
                //Table1.Rows.Add(r);
                tbl.Rows.Add(r);
                //Session["tbl"] = Table1;
            }
            //Session["tbl"] = Table1;
        }
    Retriving the table information on this button click to save in the DB
    Gives header information as it is already in .aspx page but not the cell information added from the above button click

    Code:
     protected void btnSave_Click(object sender, EventArgs e)
        {
            DocWizProjectControl pj = new DocWizProjectControl();
            pj.CreatedBy = "ADMIN";
            //Table table = new Table();
            //table = (Table) Session["tbl"];
            int rowCount = tbl.Rows.Count;
            for (int i = 0; i < rowCount; i++)
            {
                //string doc_type_id = tbl.Rows[i].Cells[0].Text;
                string document_name = tbl.Rows[i].Cells[1].Text;
            }
        }
  • mylog
    New Member
    • Sep 2007
    • 20

    #2
    Originally posted by mylog
    hi,
    I have a problem regarding the retrieval of data from a table.
    Here's is what I am doing.
    I have a created a table and from added the rows and columns and also data dynamically from the code in one of the function. Now I need to access that table and data on a button click, i.e. when a user clicks button I must be able to get the table information cell-wise. I have written the following code and when the user clicks the button all I get is the row count (i.e. no. of rows in the table are correct) but I cannot retrieve the cell information (or I have to say they are all empty). I have also tried to put the table into one Session but it also returned the same result. So is there any way this can be done. Does anyone has any idea about this.
    Help required urgently

    Looking forward to your support
    Thanks

    Inserting into table at button click

    Code:
    protected void btnAdvance_Click(object sender, EventArgs e)
        {
            Hashtable hsh = (Hashtable)Session["documentHash"];        
            Panel1.Visible = true;
            tbl = new Table();
            Panel1.Controls.Add(tbl);
            tbl.GridLines = GridLines.Both;
            int docListCount = AssocDocList.Items.Count;
            TableRow tr = new TableRow();
            TableCell tc1 = new TableCell();
            TableCell tc2 = new TableCell();
            TableCell tc3 = new TableCell();
            tc1.Controls.Add(new LiteralControl("Document Type ID"));
            tr.Cells.Add(tc1);
            tc2.Controls.Add(new LiteralControl("Document ID"));
            tr.Cells.Add(tc2);
            tc3.Controls.Add(new LiteralControl("Display Type"));
            tr.Cells.Add(tc3);
            tbl.Rows.Add(tr);
            for (int j = 0; j < docListCount; j++)
            {
                DropDownList ddl = new DropDownList();
                ddl.ID = "drop" + j;
                ddl.Items.Clear();
                ddl.Items.Add("PP");
                ddl.Items.Add("PD");
                ddl.Items.Add("DP");
                ddl.Items.Add("DD");
                TableRow r = new TableRow();            
                for (int i = 0; i < 3; i++)
                {
                    TableCell c = new TableCell();
                    if (i == 0)
                        c.Controls.Add(new LiteralControl(hsh[AssocDocList.Items[j].Text].ToString()));
                    else if (i == 1)
                        c.Controls.Add(new LiteralControl(AssocDocList.Items[j].Text));
                    else
                        c.Controls.Add(ddl);                    
    
                    r.Cells.Add(c);
                }
                //Table1.Rows.Add(r);
                tbl.Rows.Add(r);
                //Session["tbl"] = Table1;
            }
            //Session["tbl"] = Table1;
        }
    Retriving the table information on this button click to save in the DB
    Gives header information as it is already in .aspx page but not the cell information added from the above button click

    Code:
     protected void btnSave_Click(object sender, EventArgs e)
        {
            DocWizProjectControl pj = new DocWizProjectControl();
            pj.CreatedBy = "ADMIN";
            //Table table = new Table();
            //table = (Table) Session["tbl"];
            int rowCount = tbl.Rows.Count;
            for (int i = 0; i < rowCount; i++)
            {
                //string doc_type_id = tbl.Rows[i].Cells[0].Text;
                string document_name = tbl.Rows[i].Cells[1].Text;
            }
        }

    Doesn't anyone know what the problem is with this code and why I am failing to get the required output? Please help needed greatly.

    Comment

    • kenobewan
      Recognized Expert Specialist
      • Dec 2006
      • 4871

      #3
      If I was going to do this I would probably populate the table in the page load and then only make the panel visble on the button click to show the results. HTH.

      Comment

      • mylog
        New Member
        • Sep 2007
        • 20

        #4
        That may not be possible as I need to generate table depending upon the number of lists in a listbox the user selects and then get the values generated on that table. So any other idea, please
        But thanks for trying.

        Comment

        Working...