Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
90
GridRecrodCollection to DataTable
posted

Hi,

I want to iterate the WebDataGrid.Rows collection and convert it into DataTable. I am using Infragistics V11.1 version.

example:

foreach(GridRecrod recrod in WebDataGrid1.Rows)

{

          DataRowView row=(DataRowView)record;

          DataRow r=row.Row;

}

I want to type cast GridRecord to DataRow which I am not able to do. 

So kindly help keeping in mind that I am using v11.1 and want to convert GridRecordCollection to DataTable.

Please help me with this

Thanks,

Manoj

Parents
  • 17590
    Verified Answer
    Offline posted

    Hello Man,

    Thank you for posting in the community.

    Since DataRow and GridRecord are significantly different objects with very differing properties what I can suggest for achieving your requirement is creating a new DataRow object and populating it with the values from the GridRecord object.  For example:

    protected void Button1_Click(object sender, EventArgs e)

    {

    DataTable tableFromGridRows = new DataTable();

    tableFromGridRows.Columns.Add("ID");

    tableFromGridRows.Columns.Add("Name");

    DataRow dr;

    foreach(GridRecord gr in WebDataGrid1.Rows)

    {

    dr = tableFromGridRows.NewRow();

    dr["ID"] = gr.Items[0].Text;

    dr["Name"] = gr.Items[1].Text;

    tableFromGridRows.Rows.Add(dr);

    }

    }

    I made a small sample project illustrating my suggestion and I am attaching it for your reference.

    In my sample on a button click I am looping trough the grid rows, I am taking cell values and I am assigning these values to a new row of type DataRow. In the end the result is a table populated with the same rows as the WebDataGrid.

    I hope you find this information helpful.

    Please let me know if you need any further assistance with this matter.

    Regards,

    Vasya Kacheshmarova

    Developer Support Engineer

    Infragistics

    WDGCreateDataRowsFromGridRecords.zip
Reply Children