<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'How to display variable data in dynamic textbox' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'How to display variable data in dynamic textbox' posted on the 'ASP.NET' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 25 May 2013 23:36:02 -0700</pubDate>
    <lastBuildDate>Sat, 25 May 2013 23:36:02 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>How to display variable data in dynamic textbox</title>
      <link>http://www.programmersheaven.com/mb/ASPNET/428133/428133/how-to-display-variable-data-in-dynamic-textbox/</link>
      <description>Hi&lt;br /&gt;
&lt;br /&gt;
How can add display data from 4 variables in a dynamically created textbox which is inside dynamically created table, row and cell here is the code which is working fine and adding text also at the time of textbox creation but I want to add different variable values in these textbox.&lt;br /&gt;
&lt;br /&gt;
I have only 1 button on my page and on click event following code executed -&lt;pre class="sourcecode"&gt;
private int numOfRows = 1; 
   &lt;strong&gt;int a = 1; int b = 2; int c = 3; int d = 4;&lt;/strong&gt; 
protected void Page_Load(object sender, EventArgs e) 
    { 
        if (!Page.IsPostBack) 
        { 
            GenerateTable(numOfRows); 
        } 
    } 
 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
        if (ViewState["RowsCount"] != null) 
        { 
            numOfRows = Convert.ToInt32(ViewState["RowsCount"].ToString())
; 
            GenerateTable(numOfRows); 
        } 
    } 
    private void GenerateTable(int rowsCount) 
    { 
        //Creat the Table and Add it to the Page 
        Table table = new Table(); 
        table.ID = "Table1"; 
        Page.Form.Controls.Add(table); 
 
        //The number of Columns to be generated 
        const int colsCount = 4;//change the value based on you requirements 
 
        // Now iterate through the table and add your controls 
 
        for (int i = 0; i &amp;lt; rowsCount; i++) 
        { 
            TableRow row = new TableRow(); 
            for (int j = 0; j &amp;lt; colsCount; j++) 
            { 
                TableCell cell = new TableCell(); 
                TextBox tb = new TextBox(); 
                tb.Text = "RowNo:" + i + " " + "ColumnNo:" + " " + j; // Set a unique ID for each TextBox added 
                tb.ID = "TextBoxRow_" + i + "Col_" + j; 
                string cellid = tb.ID; 
 
                // Add the control to the TableCell 
                cell.Controls.Add(tb); 
                // Add the TableCell to the TableRow 
                 
                row.Cells.Add(cell); 
            } 
 
            // And finally, add the TableRow to the Table 
            &lt;strong&gt;table.Rows.Add(row); 
	      for (int k = i; k &amp;lt;= i; k++) 
	      { 
    		a++; b++; c++; d++; 
                 for (int m = 0; m &amp;lt; 4; m++) 
	        { 
		   textboxid="TextBoxRow_" + k + "Col_" + m; 
		   ((TextBox)this.FindControl(textboxid)).Text = a.ToString(); 
	        } 
               }&lt;/strong&gt;
        } 
 
        //Set Previous Data on PostBacks 
        SetPreviousData(rowsCount, colsCount); 
 
        //Sore the current Rows Count in ViewState 
        rowsCount++; 
        ViewState["RowsCount"] = rowsCount; 
    } 
 
    private void SetPreviousData(int rowsCount, int colsCount) 
    { 
        Table table = (Table)Page.FindControl("Table1"); 
        if (table != null) 
        { 
            for (int i = 0; i &amp;lt; rowsCount; i++) 
            { 
                for (int j = 0; j &amp;lt; colsCount; j++) 
                { 
                    //Extracting the Dynamic Controls from the Table 
                    TextBox tb = (TextBox)table.Rows[i].Cells[j].FindControl("TextB
oxRow_" + i + "Col_" + j); 
                    //Use Request objects for getting the previous data of the dynamic textbox 
                    //tb.Text = Request.Form["TextBoxRow_" + i + "Col_" + j]; 
                } 
            } 
        } 
    }
&lt;/pre&gt;&lt;br /&gt;
I am able to view the value of variable "a" only in all 4 textbox in a single row like this on click of button -&lt;br /&gt;
&lt;br /&gt;
       cell1     cell2      cell3     cell4&lt;br /&gt;
Row1    2            2          2          2&lt;br /&gt;
Row2    3            3          3          3&lt;br /&gt;
Row3    4            4          4          4&lt;br /&gt;
&lt;br /&gt;
......&lt;br /&gt;
&lt;br /&gt;
I just want to view the values of all 4 variables "a", "b", "c" and "d" in &lt;br /&gt;
       cell1     cell2      cell3     cell4&lt;br /&gt;
Row1    2         3          4          5        Value of a,b,c,d&lt;br /&gt;
Row2    3           4          5          6&lt;br /&gt;
Row3    4           5          6          7&lt;br /&gt;
&lt;br /&gt;
......&lt;br /&gt;
&lt;br /&gt;
Hope some body guide me.&lt;br /&gt;
&lt;br /&gt;
Regards&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/ASPNET/428133/428133/how-to-display-variable-data-in-dynamic-textbox/</guid>
      <pubDate>Tue, 03 Apr 2012 20:03:49 -0700</pubDate>
      <category>ASP.NET</category>
    </item>
  </channel>
</rss>