title: ASP.NET C# can't retrieve info from programmatically added control in GridView tablecell
body: <p>Im working on a small project and im programmatically switching text in a gridview with a control.</p>
  
  <p>Here are the steps for the code:<br/></p>
  
  <pre><code>private GridViewRow EnterEditMode(GridView GV, int RowIndex) 
      {
      GridViewRow GVR = GV.Rows[RowIndex];
      foreach (TableCell TC in GVR.Cells)
      {
          if (TC == GVR.Cells[2])
          {                        
      PlaceHolder PH = new PlaceHolder();
      string CellContent1 = TC.Text;
      DropDownList DDL = new DropDownList();
      foreach (object s in Enum.GetValues(typeof(Ticket_Status)))
      {
      DDL.Items.Add(s.ToString());
      }
      DDL.SelectedValue = CellContent1;
      DDL.ID = "I_Status_CB";
      DDL.ViewStateMode = System.Web.UI.ViewStateMode.Enabled;
      PH.ID = "PH_Status_CB";
      PH.ViewStateMode = System.Web.UI.ViewStateMode.Enabled;
      PH.Controls.Add(DDL);
      this.Page.Controls.Add(PH);
      TC.Controls.Add(PH);
          }
      } 
  }
  </code></pre>
  
  <p><strong>Now here's the problem:</strong></p>
  
  <p>Im creating a controll and replacing text in a tablecell with that created control.<br/>
  The problem is that i can't find a way to get a value from that created control!<br/>
  I've tried every method i know of, i've tried to use FindControl() normal and recursive for a row, the entire table and the cell itself. <br/>     </p>
  
  <p>If you can spot the problem or if you have any thought on this problem please reply!</p>
  
  <p><strong>Friendly greetings,</strong></p>
  
  <p><em>-Raybbo.</em></p>
  
  <p><strong>EDIT:</strong><br/>
  <br/>
  It seems that i haven't given you enough information to solve this problem with me. <br/>
  First thing i did was binding infromation from a SQL Database to declared BoundFields in the gridview.<br/></p>
  
  <pre><code>  private void GetTable()
          {
              var Tg = Ticket_Table;
              if (sCon != null &amp;&amp; sCon.State == ConnectionState.Open)
              {            
                  string SQL_Command = "SELECT * FROM Ticket_Table_2013";
                  SqlDataSource sDsc = new SqlDataSource(SQL_ConnectString, SQL_Command);
                  SqlDataAdapter sDap = new SqlDataAdapter(SQL_Command,sCon);
                  DataTable DT = new DataTable();
                  sDap.Fill(DT);            
  
                  //This is where i'm adding extra columns for additional commands.
                  Tg.DataSource = DT;
                  Tg.DataBind();
                  sDap.Dispose();
                  sDsc.Dispose();
              }
              else { CONNECT(SQL_ConnectString); GetTable(); }
          }
  </code></pre>
  
  <p>
  And here's the ASP.Net code:<br/></p>
  
  <pre><code>&lt;asp:GridView 
      ID="Ticket_Table" 
      CssClass="TableStyle" 
      ViewStateMode="Enabled" 
      runat="server" 
      OnRowUpdating="Ticket_Table_OnRowUpdating"
  
      OnSelectedIndexChanged="Ticket_Table_OnSelectedIndexChanged"
      AutoGenerateColumns="false"
      AllowPaging="true"
      &gt;
      &lt;HeaderStyle CssClass="bgBlack02 black center"/&gt;  
      &lt;RowStyle CssClass="bgBlack01 center" /&gt;
      &lt;SelectedRowStyle CssClass="bgBlack02" /&gt;
      &lt;Columns&gt;
          &lt;asp:TemplateField&gt;
              &lt;ItemTemplate&gt;
                  &lt;div class="CmdImgWrap" id="CommandBox" runat="server"&gt;
                      &lt;asp:ImageButton ID="I_Remove" CssClass="CmdImg" ImageUrl="style/Icons/Trashcan.png" runat="server" ToolTip="Remove entire row." OnClick="I_Remove_OnClick"/&gt;
                      &lt;asp:ImageButton ID="I_Edit" CssClass="CmdImg" ImageUrl="style/Icons/EditFile.png" runat="server" ToolTip="Enable edit mode." OnClick="I_Edit_OnClick"/&gt;
                      &lt;asp:ImageButton ID="I_Accept" CssClass="CmdImg" ImageUrl="style/Icons/Accept.png" Visible="false" runat="server" ToolTip="Accept changes." OnClick="I_Accept_OnClick"/&gt;
                      &lt;asp:ImageButton ID="I_Cancel" CssClass="CmdImg" ImageUrl="style/Icons/Cancel.png" Visible="false" runat="server" ToolTip="Disgard changed." OnClick="I_Cancel_OnClick"/&gt;
                      &lt;asp:ImageButton ID="I_Highlight" CssClass="CmdImg" ImageUrl="style/Icons/HighLight.png" runat="server" ToolTip="Highlight entire row."  OnClick="I_Highlight_OnClick"/&gt;
                  &lt;/div&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:BoundField DataField="Ticket_ID" HeaderText="Ticket ID" SortExpression="Ticket_ID" /&gt;
          &lt;asp:BoundField DataField="Ticket_Status" HeaderText="Ticket status" SortExpression="Ticket_Status" /&gt;
          &lt;asp:BoundField DataField="Ticket_Title" HeaderText="Ticket title" SortExpression="Ticket_Title" /&gt;
          &lt;asp:BoundField DataField="Ticket_Description" HeaderText="Description" SortExpression="Ticket_Description" /&gt;
          &lt;asp:BoundField DataField="CompanyName" HeaderText="Company name" SortExpression="CompanyName" /&gt;
      &lt;/Columns&gt;
      &lt;PagerTemplate&gt;
          &lt;asp:Button ID="Previous" runat="server" CommandName="Previous" Text="&lt;"/&gt;
          &lt;asp:Button ID="Next" runat="server" CommandName="Next" Text="&gt;"/&gt;
          &lt;asp:Button ID="Refresh" runat="server" CommandName="Refresh" Text="Refresh" /&gt;
          &lt;asp:Button ID="Update" runat="server" CommandName="Update" Text="Update" /&gt;
      &lt;/PagerTemplate&gt;
  &lt;/asp:GridView&gt;
  </code></pre>