DataTable dt = new DataTable();
DataColumn dc = new DataColumn();
dc.ColumnName = "ID";
dc.DataType = Type.GetType("System.Int32");
DataColumn dc2 = new DataColumn();
dc2.ColumnName = "Name";
dc2.DataType = Type.GetType("System.String");
dt.Columns.Add(dc);
dt.Columns.Add(dc2);
DataRow dr = dt.NewRow();
dr[0] = 1;
dr[1] = "MJ";
DataRow dr2 = dt.NewRow();
dr2[0] = 2;
dr2["Name"] = "LY";
dt.Rows.Add(dr);
dt.Rows.Add(dr2);
GridView1.DataSource = dt;
GridView1.DataBind();
DataRow[] dr3 = dt.Select("Name='MJ'");
DataTable dt2 = dt.Clone();
/*DataColumn dc3 = new DataColumn();
dc3.ColumnName = "ID";
dc3.DataType = Type.GetType("System.Int32");
DataColumn dc4 = new DataColumn();
dc4.ColumnName = "Name";
dc4.DataType = Type.GetType("System.String");
dt2.Columns.Add(dc3);
dt2.Columns.Add(dc4);*/
for (int i=0;i<dr3.Length;i++)
{
dt2.ImportRow(dr3[i]);
}
if (dt2.Rows.Count > 0)
{
foreach (DataRow dr5 in dt2.Rows)
{
Response.Write(dr5[0].ToString());
}
}
GridView2.DataSource = dt2;
GridView2.DataBind();
Response.Write(dr3[0]["ID"].ToString());