473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

ASP Table Problem C#

20
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

Expand|Select|Wrap|Line Numbers
  1. protected void btnAdvance_Click(object sender, EventArgs e)
  2.     {
  3.         Hashtable hsh = (Hashtable)Session["documentHash"];        
  4.         Panel1.Visible = true;
  5.         tbl = new Table();
  6.         Panel1.Controls.Add(tbl);
  7.         tbl.GridLines = GridLines.Both;
  8.         int docListCount = AssocDocList.Items.Count;
  9.         TableRow tr = new TableRow();
  10.         TableCell tc1 = new TableCell();
  11.         TableCell tc2 = new TableCell();
  12.         TableCell tc3 = new TableCell();
  13.         tc1.Controls.Add(new LiteralControl("Document Type ID"));
  14.         tr.Cells.Add(tc1);
  15.         tc2.Controls.Add(new LiteralControl("Document ID"));
  16.         tr.Cells.Add(tc2);
  17.         tc3.Controls.Add(new LiteralControl("Display Type"));
  18.         tr.Cells.Add(tc3);
  19.         tbl.Rows.Add(tr);
  20.         for (int j = 0; j < docListCount; j++)
  21.         {
  22.             DropDownList ddl = new DropDownList();
  23.             ddl.ID = "drop" + j;
  24.             ddl.Items.Clear();
  25.             ddl.Items.Add("PP");
  26.             ddl.Items.Add("PD");
  27.             ddl.Items.Add("DP");
  28.             ddl.Items.Add("DD");
  29.             TableRow r = new TableRow();            
  30.             for (int i = 0; i < 3; i++)
  31.             {
  32.                 TableCell c = new TableCell();
  33.                 if (i == 0)
  34.                     c.Controls.Add(new LiteralControl(hsh[AssocDocList.Items[j].Text].ToString()));
  35.                 else if (i == 1)
  36.                     c.Controls.Add(new LiteralControl(AssocDocList.Items[j].Text));
  37.                 else
  38.                     c.Controls.Add(ddl);                    
  39.  
  40.                 r.Cells.Add(c);
  41.             }
  42.             //Table1.Rows.Add(r);
  43.             tbl.Rows.Add(r);
  44.             //Session["tbl"] = Table1;
  45.         }
  46.         //Session["tbl"] = Table1;
  47.     }
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

Expand|Select|Wrap|Line Numbers
  1.  protected void btnSave_Click(object sender, EventArgs e)
  2.     {
  3.         DocWizProjectControl pj = new DocWizProjectControl();
  4.         pj.CreatedBy = "ADMIN";
  5.         //Table table = new Table();
  6.         //table = (Table) Session["tbl"];
  7.         int rowCount = tbl.Rows.Count;
  8.         for (int i = 0; i < rowCount; i++)
  9.         {
  10.             //string doc_type_id = tbl.Rows[i].Cells[0].Text;
  11.             string document_name = tbl.Rows[i].Cells[1].Text;
  12.         }
  13.     }
Mar 7 '08 #1
3 1855
mylog
20
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

Expand|Select|Wrap|Line Numbers
  1. protected void btnAdvance_Click(object sender, EventArgs e)
  2.     {
  3.         Hashtable hsh = (Hashtable)Session["documentHash"];        
  4.         Panel1.Visible = true;
  5.         tbl = new Table();
  6.         Panel1.Controls.Add(tbl);
  7.         tbl.GridLines = GridLines.Both;
  8.         int docListCount = AssocDocList.Items.Count;
  9.         TableRow tr = new TableRow();
  10.         TableCell tc1 = new TableCell();
  11.         TableCell tc2 = new TableCell();
  12.         TableCell tc3 = new TableCell();
  13.         tc1.Controls.Add(new LiteralControl("Document Type ID"));
  14.         tr.Cells.Add(tc1);
  15.         tc2.Controls.Add(new LiteralControl("Document ID"));
  16.         tr.Cells.Add(tc2);
  17.         tc3.Controls.Add(new LiteralControl("Display Type"));
  18.         tr.Cells.Add(tc3);
  19.         tbl.Rows.Add(tr);
  20.         for (int j = 0; j < docListCount; j++)
  21.         {
  22.             DropDownList ddl = new DropDownList();
  23.             ddl.ID = "drop" + j;
  24.             ddl.Items.Clear();
  25.             ddl.Items.Add("PP");
  26.             ddl.Items.Add("PD");
  27.             ddl.Items.Add("DP");
  28.             ddl.Items.Add("DD");
  29.             TableRow r = new TableRow();            
  30.             for (int i = 0; i < 3; i++)
  31.             {
  32.                 TableCell c = new TableCell();
  33.                 if (i == 0)
  34.                     c.Controls.Add(new LiteralControl(hsh[AssocDocList.Items[j].Text].ToString()));
  35.                 else if (i == 1)
  36.                     c.Controls.Add(new LiteralControl(AssocDocList.Items[j].Text));
  37.                 else
  38.                     c.Controls.Add(ddl);                    
  39.  
  40.                 r.Cells.Add(c);
  41.             }
  42.             //Table1.Rows.Add(r);
  43.             tbl.Rows.Add(r);
  44.             //Session["tbl"] = Table1;
  45.         }
  46.         //Session["tbl"] = Table1;
  47.     }
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

Expand|Select|Wrap|Line Numbers
  1.  protected void btnSave_Click(object sender, EventArgs e)
  2.     {
  3.         DocWizProjectControl pj = new DocWizProjectControl();
  4.         pj.CreatedBy = "ADMIN";
  5.         //Table table = new Table();
  6.         //table = (Table) Session["tbl"];
  7.         int rowCount = tbl.Rows.Count;
  8.         for (int i = 0; i < rowCount; i++)
  9.         {
  10.             //string doc_type_id = tbl.Rows[i].Cells[0].Text;
  11.             string document_name = tbl.Rows[i].Cells[1].Text;
  12.         }
  13.     }

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.
Mar 9 '08 #2
kenobewan
4,871 Expert 4TB
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.
Mar 9 '08 #3
mylog
20
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.
Mar 10 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Gaz | last post by:
Hi, I need to have a table nested within another table. The tables are alongside each other visually speaking, and the nested table (on the right) can vary in size. My problem is that when the...
61
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will...
3
by: Terrence Brannon | last post by:
I don't know what Postgres considers a relation and had no intention of creating one when piping my schema to it... I always DROP TABLE before CREATE TABLE, so here are the ERRORS emitted when...
4
by: maricel | last post by:
I have the following base table structure - DDL: CREATE TABLE "ADMINISTRATOR"."T1" ( "C1" INTEGER NOT NULL ) IN "TEST_TS" ; ALTER TABLE "ADMINISTRATOR"."T1" ADD PRIMARY KEY
4
by: Simone Battagliero | last post by:
I wrote a program which inserts and finds elements in an hash table. Each element of the table is a dinamic list, which holds all elements having the same hash value (calculated by an int...
117
by: phil-news-nospam | last post by:
Is there really any advantage to using DIV elements with float style properies, vs. the old method of TABLE and TR and TD? I'm finding that by using DIV, it still involves the same number of...
76
MMcCarthy
by: MMcCarthy | last post by:
Normalisation is the term used to describe how you break a file down into tables to create a database. There are 3 or 4 major steps involved known as 1NF (First Normal Form), 2NF (Second Normal...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.