ASP.NET Tek DataGrid’de 2 DataTable
Sayfa tasarimi :

Sayfa Tasarimi
Default.aspx.cs kodlarimiz
-
using System;
-
using System.Data;
-
using System.Data.SqlClient;
-
-
public partial class _Default : System.Web.UI.Page
-
{
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
this.TekGrid();
-
}
-
-
void TekGrid()
-
{
-
string _connectionString = "data source=localhost;initial catalog=AdventureWorks;integrated security=true";
-
-
-
SqlDataAdapter _adapter1 = new SqlDataAdapter("select ProductID,Name,ListPrice,SafetyStockLevel,Color,ProductSubcategoryID from Production.Product", _cn1);
-
SqlDataAdapter _adapter2 = new SqlDataAdapter("select ProductSubcategoryID,Name from Production.ProductSubcategory", _cn2);
-
-
{
-
{
-
AutoIncrement = true,
-
Unique = true,
-
AutoIncrementSeed = 1,
-
AutoIncrementStep = 1
-
},
-
};
-
-
_dt1.Columns.AddRange(_cl1);
-
-
{
-
{
-
AutoIncrement = true,
-
Unique = true,
-
AutoIncrementSeed = 1,
-
AutoIncrementStep = 1
-
},
-
};
-
-
_dt2.Columns.AddRange(_cl2);
-
-
{
-
"kenan","myfan","yourfan","irfan","coder","şimdi uzaklardasin"
-
};
-
-
{
-
"kalfa","dedikodu","liar","pinokyo"
-
};
-
-
{
-
"moda","yenidogan","tandogan","kordon","maslak"
-
};
-
-
{
-
"istanbul","ankara","izmir"
-
};
-
-
for (int i = 0; i < 10; i++)
-
{
-
DataRow _row = _dt1.NewRow();
-
-
_row["Name"] = _names[rnd.Next(0, _names.Length)];
-
_row["SurName"] = _surNames[rnd.Next(0, _surNames.Length)];
-
_dt1.Rows.Add(_row);
-
System.Threading.Thread.Sleep(10);
-
}
-
-
for (int i = 0; i < 10; i++)
-
{
-
DataRow _row = _dt2.NewRow();
-
-
_row["Address"] = _adresses[rnd.Next(0, _adresses.Length)];
-
_row["City"] = _cities[rnd.Next(0, _cities.Length)];
-
_dt2.Rows.Add(_row);
-
System.Threading.Thread.Sleep(10);
-
}
-
-
-
_dt1.Merge(_dt2, false, MissingSchemaAction.AddWithKey);
-
-
myGrid.DataSource = _dt1;
-
myGrid.DataBind();
-
}
-
}
Çıktı :

One Grid,Multi DataTable