title: How to Bind Selected Rows From Grid View to Another Grid View
body: <p>I would to add the selected rows from gridview into another gridview. Could someone help me on this? When I try to bind gridview to another gridview, another gridview doesn't appear. </p>
  
  <p>The aspx file I posted below is about how I created the gridview. The gridview1 will get its gridview contents from the database table. While the cs file is about how I am going to bind selected rows from gridview1 into gridview2. The problem now is when I try to bind the rows over, the gridview2 didn't appear, only gridview1 appeared.  </p>
  
  <p>This is my codes:</p>
  
  <p><strong>ASPX file:</strong></p>
  
  <pre><code>&lt;h3 class="h3"&gt;Grid View1&lt;/h3&gt;
  &lt;div style="width: 100%; height: 400px; overflow: auto"&gt;
      &lt;asp:GridView ID="GridView1"
                    runat="server"
                    AllowSorting="True"
                    AutoGenerateColumns="False"
                    Width="100%"
                    CellPadding="6"
                    ForeColor="#333333"
                    GridLines="Horizontal"
                    BorderColor="Black"
                    BorderStyle="Solid"
                    BorderWidth="2px"
                    EmptyDataText="Record Not Found"
                    OnRowDataBound="GridView1_OnRowDataBound"&gt;
          &lt;AlternatingRowStyle BackColor="White" /&gt;
          &lt;Columns&gt;
              &lt;asp:BoundField DataField="DATE"
                              HeaderText="DATE"&gt;&lt;/asp:BoundField&gt;
              &lt;asp:BoundField DataField="CODE"
                              HeaderText="CODE"&gt;&lt;/asp:BoundField&gt;
              &lt;asp:BoundField DataField="PROFILE_NAME"
                              HeaderText="PROFILE_NAME"&gt;&lt;/asp:BoundField&gt;
              &lt;asp:BoundField DataField="DESCRIPTION"
                              HeaderText="DESCRIPTION"&gt;&lt;/asp:BoundField&gt;
              &lt;asp:BoundField DataField="STATUS"
                              HeaderText="STATUS"&gt;&lt;/asp:BoundField&gt;
              &lt;asp:BoundField DataField="USER"
                              HeaderText="USER"&gt;&lt;/asp:BoundField&gt;
              &lt;asp:BoundField DataField="SUB_USER"
                              HeaderText="SUB_USER"&gt;&lt;/asp:BoundField&gt;
              &lt;asp:BoundField DataField="SCORE"
                              HeaderText="SCORE"&gt;&lt;/asp:BoundField&gt;
              &lt;asp:BoundField DataField="ROLE"
                              HeaderText="ROLE"&gt;&lt;/asp:BoundField&gt;
              &lt;asp:BoundField DataField="QUANTITY"
                              HeaderText="QUANTITY"&gt;&lt;/asp:BoundField&gt;
              &lt;asp:BoundField DataField="ITEM"
                              HeaderText="ITEM"&gt;&lt;/asp:BoundField&gt;
              &lt;asp:BoundField DataField="PRICE"
                              HeaderText="PRICE"&gt;&lt;/asp:BoundField&gt;
          &lt;/Columns&gt;
          &lt;EditRowStyle BackColor="#2461BF" /&gt;
          &lt;FooterStyle BackColor="#507CD1"
                       Font-Bold="False"
                       ForeColor="Black" /&gt;
          &lt;HeaderStyle BackColor="#507CD1"
                       Font-Bold="False"
                       ForeColor="Black"
                       BorderStyle="Solid"
                       BorderWidth="2px" /&gt;
          &lt;PagerStyle BackColor="#2461BF"
                      ForeColor="White"
                      HorizontalAlign="Center" /&gt;
          &lt;RowStyle BackColor="#EFF3FB" /&gt;
          &lt;SelectedRowStyle BackColor="#D1DDF1"
                            Font-Bold="False"
                            ForeColor="#333333" /&gt;
          &lt;SortedAscendingCellStyle BackColor="#F5F7FB" /&gt;
          &lt;SortedAscendingHeaderStyle BackColor="#6D95E1" /&gt;
          &lt;SortedDescendingCellStyle BackColor="#E9EBEF" /&gt;
          &lt;SortedDescendingHeaderStyle BackColor="#4870BE" /&gt;
      &lt;/asp:GridView&gt;
      &lt;h3 class="h3"&gt;Grid View2&lt;/h3&gt;
      &lt;div style="width: 100%; height: 400px; overflow: auto"&gt;
          &lt;asp:GridView ID="GridView2"
                        runat="server"
                        AllowSorting="True"
                        AutoGenerateColumns="False"
                        Width="100%"
                        CellPadding="6"
                        ForeColor="#333333"
                        GridLines="Horizontal"
                        BorderColor="Black"
                        BorderStyle="Solid"
                        BorderWidth="2px"
                        EmptyDataText="Record Not Found"
                        OnRowDataBound="GridView2_OnRowDataBound"&gt;
              &lt;AlternatingRowStyle BackColor="White" /&gt;
              &lt;Columns&gt;
                  &lt;asp:BoundField DataField="DATE"
                                  HeaderText="DATE"&gt;&lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="CODE"
                                  HeaderText="CODE"&gt;&lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="PROFILE_NAME"
                                  HeaderText="PROFILE_NAME"&gt;&lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="DESCRIPTION"
                                  HeaderText="DESCRIPTION"&gt;&lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="STATUS"
                                  HeaderText="STATUS"&gt;&lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="USER"
                                  HeaderText="USER"&gt;&lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="SUB_USER"
                                  HeaderText="SUB_USER"&gt;&lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="SCORE"
                                  HeaderText="SCORE"&gt;&lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="ROLE"
                                  HeaderText="ROLE"&gt;&lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="QUANTITY"
                                  HeaderText="QUANTITY"&gt;&lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="ITEM"
                                  HeaderText="ITEM"&gt;&lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="PRICE"
                                  HeaderText="PRICE"&gt;&lt;/asp:BoundField&gt;
              &lt;/Columns&gt;
              &lt;EditRowStyle BackColor="#2461BF" /&gt;
              &lt;FooterStyle BackColor="#507CD1"
                           Font-Bold="False"
                           ForeColor="Black" /&gt;
              &lt;HeaderStyle BackColor="#507CD1"
                           Font-Bold="False"
                           ForeColor="Black"
                           BorderStyle="Solid"
                           BorderWidth="2px" /&gt;
              &lt;PagerStyle BackColor="#2461BF"
                          ForeColor="White"
                          HorizontalAlign="Center" /&gt;
              &lt;RowStyle BackColor="#EFF3FB" /&gt;
              &lt;SelectedRowStyle BackColor="#D1DDF1"
                                Font-Bold="False"
                                ForeColor="#333333" /&gt;
              &lt;SortedAscendingCellStyle BackColor="#F5F7FB" /&gt;
              &lt;SortedAscendingHeaderStyle BackColor="#6D95E1" /&gt;
              &lt;SortedDescendingCellStyle BackColor="#E9EBEF" /&gt;
              &lt;SortedDescendingHeaderStyle BackColor="#4870BE" /&gt;
          &lt;/asp:GridView&gt;
  </code></pre>
  
  <p><strong>CS file:</strong></p>
  
  <pre><code>protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs     e)
  {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
          if (Convert.ToString(DataBinder.Eval(e.Row.DataItem, “USER”)) == “ALAN TAN”)
          {
              DataTable dt = new DataTable();
              dt.Columns.Add(“DATE”);
              dt.Columns.Add(“CODE”);
              dt.Columns.Add(“PROFILE_NAME”);
  
              dt.Columns.Add(“DESCRIPTION”);
              dt.Columns.Add(“STATUS”);
              dt.Columns.Add(“USER”);
              dt.Columns.Add(“SUB_USER”);
              dt.Columns.Add(“SCORE”);
              dt.Columns.Add(“ROLE”);
              dt.Columns.Add(“QUANTITY”);
              dt.Columns.Add(“ITEM”);
              dt.Columns.Add(“PRICE”);
              DataRow dataRow;
              dataRow = dt.NewRow();
              int i2 = 1;
              for(int i=0; i&lt;dataRow.Table.Columns.Count; i++)
              {
                  dataRow[i] = GridView1.SelectedRow.Cells[i2].Text;
                  i2++;
              }
              dt.Rows.Add(dataRow);
              GridView2.DataSource = dt;
              GridView2.DataBind();
          }
      }
  }
  </code></pre>
  
  <p>Any help is greatly appreciated. Thanks!</p>