This is a migrated thread and some comments may be shown as answers.

radgrid to datatable

1 Answer 1044 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mohammad
Top achievements
Rank 1
mohammad asked on 03 Mar 2009, 06:06 AM
Hello
How do i want to convert grid data  after filtering to datatable?
How do i want to use  datatable instead grid after filtering?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Mar 2009, 11:47 AM
Hi Mohammad,

You can store the DataTable that you using to bind the Grid to a ViewState. In a button click event you can clear the rows of the DataTable and add new rows according to the rows present in the Grid.

CS:
  
 
 public DataTable dt = new DataTable(); 
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        string connectionstring = "Data Source=inc156; Initial Catalog=NorthWind;User ID=rt; Password=rt"
        SqlConnection conn = new SqlConnection(connectionstring); 
        SqlCommand cmd = new SqlCommand(); 
        conn.Open(); 
        SqlDataAdapter adp1 = new SqlDataAdapter("select  ProductID,ProductName from  Products ", conn); 
        
        adp1.Fill(dt); 
        RadGrid1.DataSource = dt; 
        ViewState["dt"] = dt; 
        conn.Close(); 
    } 
 
    protected void Button2_Click(object sender, EventArgs e) 
   { 
 
       DataTable dt = (DataTable)ViewState["dt"]; 
       dt.Rows.Clear(); 
 
       foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
       { 
           DataRow newRow = dt.NewRow(); 
           foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
           { 
               if (col.ColumnType == "GridBoundColumn"
               { 
                   string unique = col.UniqueName; 
                   newRow[unique] = item[unique].Text; 
 
               } 
 
 
           } 
           dt.Rows.Add(newRow); 
 
 
       } 
 
 
       RadGrid2.DataSource = dt; 
       RadGrid2.DataBind(); 
             
         
         
    } 


Regards
Shinu.
Tags
Grid
Asked by
mohammad
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or