473,786 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrive data from dynamically created table

210 Recognized Expert New Member
I have created two tables dynamically and have added textboxes inside the table. now i am trying to retrieve the data from the the textboxes and i am getting a null reference error. I am not sure why i am getting this error. Please advice.

Code to set the tables

Expand|Select|Wrap|Line Numbers
  1.  
  2.  protected void LoadCityStateControl(int origin, int destination)
  3.     {
  4.         //initializing the origin city/state controls
  5.         Table city = new Table();
  6.         city.ID = "tblcity";
  7.         city.BorderStyle = BorderStyle.Solid;
  8.         city.BorderWidth = 1;
  9.  
  10.  
  11.         for (int i = 0; i < origin; i++)
  12.         {
  13.             TableRow tr = new TableRow();
  14.             TableCell tc = new TableCell();
  15.             tc.ID = "tc" + (i + 1);
  16.             Label mx = new Label();
  17.             mx.Text = "Origin City/State #" + (i + 1) + " : ";
  18.             mx.ID = "lblorgcitystate" + (i + 1);
  19.  
  20.             TextBox tx = new TextBox();
  21.             tx.ID = "txtOrgCityState" + (i + 1);
  22.  
  23.             Label mn = new Label();
  24.             mn.ID = "lbltest" + (i + 1);
  25.             mn.Text = "  (eg: Cape Girardeau,MO )";
  26.  
  27.             tc.Controls.Add(mx);
  28.             tc.Controls.Add(tx);
  29.             tc.Controls.Add(mn);
  30.             tr.Cells.Add(tc);
  31.             city.Rows.Add(tr);
  32.         }
  33.         cpanel.Controls.Add(city);
  34.  
  35.         //initializing the destination city/state controls
  36.         Table descity = new Table();
  37.         descity.ID = "tbldescity";
  38.         descity.BorderStyle = BorderStyle.Solid;
  39.         descity.BorderWidth = 1;
  40.  
  41.         for (int i = 0; i < destination; i++)
  42.         {
  43.             TableRow trd = new TableRow();
  44.             TableCell tcd = new TableCell();
  45.             tcd.ID = "tcd" + (i + 1);
  46.             Label mxd = new Label();
  47.             mxd.Text = "Destination City/State #" + (i + 1) + " : ";
  48.             mxd.ID = "lbldestcitystate" + (i + 1);
  49.  
  50.             TextBox txd = new TextBox();
  51.             txd.ID = "txtDestCityState" + (i + 1);
  52.  
  53.             Label mnd = new Label();
  54.             mnd.ID = "lbldtest" + (i + 1);
  55.             mnd.Text = "  (eg: Dallas,TX )";
  56.  
  57.             tcd.Controls.Add(mxd);
  58.             tcd.Controls.Add(txd);
  59.             tcd.Controls.Add(mnd);
  60.             trd.Cells.Add(tcd);
  61.             descity.Rows.Add(trd);
  62.         }
  63.         cpanel.Controls.Add(descity);
  64.  
  65.  
  66.     }
  67.  
Here is the code to retrieve data

Expand|Select|Wrap|Line Numbers
  1.         int orgcounter = Int32.Parse(txtNumPicks.Text);
  2.         int descounter = Int32.Parse(txtNumDrops.Text);
  3.  
  4.         for (int i = 0; i <= orgcounter; i++)
  5.         {
  6.             foreach (Control c in cpanel.Controls)
  7.             {
  8.                  Table m = (Table)c.FindControl("tbldescity");
  9.                 foreach (TableRow r in m.Rows)
  10.                  {
  11.                     foreach (TableCell tc in r.Cells)
  12.                    {
  13.                        orgcity = ((TextBox)tc.FindControl("txtOrgCityState" +  (i).ToString())).Text;
  14.                    }
  15.  
  16.                 }
  17.             }
  18.        }
  19.  
  20.  
I just noticed that if i try to get the controls count inside the panel i get a value zero. Why is this happening.

Expand|Select|Wrap|Line Numbers
  1.  lblerr.Text = c.Controls.Count.ToString();
  2.  
Please help . Thank you in advance
Nov 5 '08 #1
2 2463
Plater
7,872 Recognized Expert Expert
When you insert/name your controls you use i+1, when you search, you are using just i, so sometimes the FindControl will return a null value since it cannot find the control
Nov 5 '08 #2
semomaniz
210 Recognized Expert New Member
I did put I+1 while searching and still i am getting the same error. I noticed that the reason why i was getting this error was i didnt set the form at page load event. The form is based on input that i get from another form. In other words i determine the count of pick and drop from a form which gets hidden after value is submitted. then the dynamically created form is displayed. If i recreate the form inside the click event of previous form submit button i still am not able to get the value from textboxes.

To avoid this i am trying to redirect the page to the same page and have the form created dynamically in the page load event. But i am still not able to retrieve data.
Nov 5 '08 #3

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

Similar topics

6
2856
by: Michael Johnson Jr. | last post by:
I am trying to handle a button click event, which updates a web control table with data. The button is dynamically created in the table itself. When I call updateTable() in the Page_Load the new data from the button is not available at this time as to allow the table to properly update. So basically, I need to call UpdateTable() twice, once from page load and once from button. This causes problems with my application, and I was trying...
2
2929
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have a WebForm with some textboxes, dropdownlists, a panel, imagebutton and so on. When I click on the image button (which was created at design time) I dynamically build a table. In each of row of that new table I put several cells and one cell...
3
5293
by: Forconi Boris via .NET 247 | last post by:
Hi, I'm working on a project in witch I have to list data(products that can be selected with a certain quantity) from anXML document, with key words entered by the user. A Table isdynamically created with text, and in each row, there 's atextBox (with an incremental ID number) in witch the user canenter a number of products. When the user clicks on the "Submit"button, I must know witch row he has selected, AND WITCH NUMBERHE HAS ENTERED in the...
3
2143
by: Tim | last post by:
Hello All, Hope someone can point me in the right direction here. I have a ASPX page that is being created dynamically. My function adds Labels and Text Boxes to a Table ready for the user to fill them in. Once the user has entered their information I need to be able to store it all in a database. The only problem I have is that by using a Web Button all the dynamically created controls disapear beacuse of the postback. My
2
1665
by: Terry | last post by:
Any .dll or COM+ for .Net can help me retrive data from a Access file? The table contain several columns and the last one is a container which I store Article; because each article is a little bit huge, so when I store it, it ask me if I want to pack it (the article) into a object then I click 'Yes'. But now I need to retrive data from the file and show it by datagrid, and now I don't know what kind of data type it is (when I click it, it...
2
2131
by: Gian Paolo | last post by:
Hi all on .net 2.0 i have a dataset and a table with some rows. Is there a way to retrive the current row index ? So i can retrive other value of that column... something like dataset.table.columnname.value regards paolo
4
2716
by: assgar | last post by:
Hi I am stuck on a problem. I use 3 scripts(form, function and process). Development on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. The form displays multiple dynamic rows with chechboxs, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply.
23
3424
nehashri
by: nehashri | last post by:
hi i am designing a database using Ms Access and ASP. i have 3 tables in access namely 'PERSONAL', other as 'POLICY' and 3rd one is named as 'STAFF'. in the contact table i have ID, Name, Children as fields. Also in policy table the firlds are:- ID, date_of_policy, no_policy, amount_paid, amount_balance and similarly the 3rd ie., staff has few fields. all three are linked my a common field which is ID all i want is when the user searches...
1
3380
by: amritranjan | last post by:
How to retrive image file from MS access database and display this in another JSPpage -------------------------------------------------------------------------------- This is my Jsp code for image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title>
0
10169
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.