// Create a DataTable and add two Columns to it DataTable dt=new DataTable(); dt.Columns.Add("Name",typeof(string)); dt.Columns.Add("Age",typeof(int)); // Create a DataRow, add Name and Age data, and add to the DataTable DataRow dr=dt.NewRow(); dr["Name"]="Mohammad"; // or dr[0]="Mohammad"; dr["Age"]=24; // or dr[1]=24; dt.Rows.Add(dr); // Create another DataRow, add Name and Age data, and add to the DataTable dr=dt.NewRow(); dr["Name"]="Shahnawaz"; // or dr[0]="Shahnawaz"; dr["Age"]=24; // or dr[1]=24; dt.Rows.Add(dr); // DataBind to your UI control, if necessary (a GridView, in this example) GridView1.DataSource=dt; GridView1.DataBind();
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter