title: datagrid add item to datasource lose viewstate
body: <p>I do have a page that has a TextBox a Button and a Datagrid.</p>
  
  <p>The goal here is simple : Each time I input something in the TextBox and press the Button, it does a little check and then it adds the item to the datagrid and a business logic datasource.</p>
  
  <p>The problem is, if I want to make the item appear in the DataGrid I have to do a datagrid.DataSource = myBusinessObject; datagrid.DataBind(); problem with that is I lose the viewstate and the choice in the radiobox the user have done.</p>
  
  <p>Here is the Template : </p>
  
  <pre><code>            &lt;asp:TextBox ID="txtDomain" runat="server" style="margin-bottom: 0px" 
                  Width="254px"&gt;&lt;/asp:TextBox&gt;
                  &amp;nbsp;&lt;asp:Button ID="domainAdd" runat="server" onclick="domainAdd_Click" 
                  style="height: 26px" Text="Ajouter" /&gt;
              &amp;nbsp;&lt;br /&gt;
              &lt;br /&gt;
              &lt;asp:DataGrid ID="dg1" runat="server" AutoGenerateColumns="false"&gt;
                  &lt;Columns&gt;
                      &lt;asp:BoundColumn DataField="Name" HeaderText="Nom choisi"&gt;&lt;/asp:BoundColumn&gt;
                      &lt;asp:TemplateColumn HeaderText="Enregistrer"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:RadioButton ID="register" runat="server" GroupName="domaine_action" Checked='&lt;%# Bind("IsRegister")%&gt;' Enabled='&lt;%# Bind("CanRegister")%&gt;' /&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateColumn&gt;
                      &lt;asp:TemplateColumn HeaderText="Transférer"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:RadioButton ID="transfert" runat="server" GroupName="domaine_action" Checked='&lt;%# Bind("IsTransfert")%&gt;' Enabled='&lt;%# Bind("CanTransfert")%&gt;' /&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateColumn&gt;
                      &lt;asp:TemplateColumn HeaderText="Gérer moi même"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:RadioButton ID="manage" runat="server" GroupName="domaine_action" Checked='&lt;%# Bind("IsSelfManaged")%&gt;' Enabled='&lt;%# Bind("CanSelfManage")%&gt;' /&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateColumn&gt;
                  &lt;/Columns&gt;
              &lt;/asp:DataGrid&gt;
  </code></pre>
  
  <p>The code behind : </p>
  
  <pre><code>    protected void domainAdd_Click(object sender, EventArgs e)
      {
          if (Session["dic"] != null)
          {
              var _dic = (List&lt;Test1&gt;)Session["dic"];
  
              _dic.Add(new Test1 { Name = txtDomain.Text });
  
              dg1.DataSource = _dic;
              dg1.DataBind();
  
              Session["dic"] = _dic;
          }
          else
          {
              List&lt;Test1&gt; _dic = new List&lt;Test1&gt;();
  
              _dic.Add(new Test1 { Name = txtDomain.Text });
  
              dg1.DataSource = _dic;
              dg1.DataBind();
  
              Session["dic"] = _dic;
          }
  </code></pre>
  
  <p>For now the Test1 object is just a little class to map fields for business logic.</p>
  
  <pre><code>public class Test1
  {
      public string Name { get; set; }
  
      public string IsRegister { get; set; }
      public string IsTransfert { get; set; }
      public string IsSelfManaged { get; set; }
  
      public string CanRegister { get; set; }
      public string CanTransfert { get; set; }
      public string CanSelfManage { get; set; }
  }
  </code></pre>
  
  <p>So I guess the direct question would be : How to add items to the grid &amp; the business object without loosing the choices of radioboxes in the grid.</p>