title: Multiple OfType Linq?
body: <p>I have a linq query that selects all textboxes in a placeholder and adds them to a list using a struct. I need to expand this functionality to also take the selectedvalue of a DropDownList I am pretty sure I am doing this wrong, because when I debug the method the lists count is 0.</p>
  
  <p>My own guess is that declaring 2 <code>OfType&lt;&gt;()</code> is wrong, but I am pretty new to linq and I have no idea of how else to do it.</p>
  
  <p>Any help would be awesome! Thanks in advance.</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>public struct content
  {
      public string name;
      public string memberNo;
      public int points;
      public string carclass;
  }
  
  List&lt;content&gt; rows = new List&lt;content&gt;();
  
  protected void LinkButton_Submit_Attendees_Click(object sender, EventArgs e)
  {
  List&lt;content&gt; rows = PlaceHolder_ForEntries.Controls.OfType&lt;TextBox&gt;().OfType&lt;DropDownList&gt;()
          .Select(txt =&gt; new
          {
              Txt = txt,
              Number = new String(txt.ID.SkipWhile(c =&gt; !Char.IsDigit(c)).ToArray())
          })
          .GroupBy(x =&gt; x.Number)
          .Select(g =&gt; new content
          {
              carclass = g.First(x =&gt; x.Txt.ID.StartsWith("DropDownlist_CarClass")).Txt.SelectedValue,
              name = g.First(x =&gt; x.Txt.ID.StartsWith("TextBox_Name")).Txt.Text,
              memberNo = g.First(x =&gt; x.Txt.ID.StartsWith("TextBox_MemberNo")).Txt.Text,
              points = int.Parse(g.First(x =&gt; x.Txt.ID.StartsWith("TextBox_Points")).Txt.Text)
          })
          .ToList();
  }
  </code></pre>
  
  <p>Here's the method that creates the controls.</p>
  
  <pre><code>protected void createcontrols()
  {
      int count = 0;
      if (ViewState["count"] != null)
      {
          count = (int)ViewState["count"];
      }
      while (PlaceHolder_ForEntries.Controls.Count &lt; count)
      {
          TextBox TextBox_Name = new TextBox();
          TextBox TextBox_MemberNo = new TextBox();
          TextBox TextBox_Points = new TextBox();
          DropDownList DropDownList_CarClass = new DropDownList();
          DropDownList_CarClass.Items.Add("Car1");
          ...
          DropDownList_CarClass.Items.Add("Car2");
          TextBox_Name.Attributes.Add("placeholder", "Navn");
          TextBox_Name.ID = "TextBox_Name" + PlaceHolder_ForEntries.Controls.Count.ToString();
          TextBox_Name.CssClass = "input-small";
          TextBox_MemberNo.Attributes.Add("placeholder", "Medlemsnr.");
          TextBox_MemberNo.ID = "TextBox_MemberNo" + PlaceHolder_ForEntries.Controls.Count.ToString();
          TextBox_MemberNo.CssClass = "input-small";
          TextBox_Points.Attributes.Add("placeholder", "Point");
          TextBox_Points.ID = "TextBox_Points" + PlaceHolder_ForEntries.Controls.Count.ToString();
          TextBox_Points.CssClass = "input-small";
          PlaceHolder_ForEntries.Controls.Add(TextBox_Name);
          PlaceHolder_ForEntries.Controls.Add(TextBox_MemberNo);
          PlaceHolder_ForEntries.Controls.Add(DropDownList_CarClass);
          PlaceHolder_ForEntries.Controls.Add(TextBox_Points);
          PlaceHolder_ForEntries.Controls.Add(new LiteralControl("&lt;br /&gt;"));
      }
  }
  </code></pre>