Saturday, May 1, 2010

How to convert Data Row to Data Row View

Converting Data Row to Data Row View is not possible, but we can go around this by using DefaultView property of the Data Row Table.

The following code example demonstrate how to get Data Row View out of Data Row:

DataTable dt = new DataTable();

dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Name", typeof(string));

for (int i = 0; i < 10; i++)
 DataRow tempDR = dt.NewRow();
 tempDR["ID"] = (i + 1);
 tempDR["Name"] = "Name " + (i + 1).ToString();

DataRow dr = dt.Rows[1]; 
DataRowView drv = dr.Table.DefaultView[dt.Rows.IndexOf(dr)];

Hire Me

Follow me on Facebook

Follow me

Do you find this Blog helpful?

Follow by Email

About Me

My Photo
Expert Senior Software Developer

Microsoft Business Card