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
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); } }
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
Previously in our project we are using UltrawebGrid and we use to apply our own formatting style for grid pointing to custom formatting folder. Now I have implemented WebDataGrid V11.1. Now I want to apply the same formatting style to the new grid. So in web.config how should specify the existing formatting folder(contain .css,images etc) as a path to the new Webdatagrid.