Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom grid LINQ to SQL

The following is my custom control grid:

public partial class LinqGrid : UserControl
{
        object tmpDataTable = new object();
        public LinqGrid()
        {
            InitializeComponent();
        }
        public void Bind<T>(System.Data.Linq.Table<T> listSource) where T : class
        {          
            Project.dbClassesDataContext dbc = new Project.dbClassesDataContext();
            tmpDataTable = listSource;
            var query = (from c in listSource select c);
            dgvRecords.DataSource = query.Take(10).ToList();
        }
        private void btnNext_Click(object sender, EventArgs e)
        {
// now what do I have to do here if I want next 10 records? I mean how to retrieve tmpDataTable object here? I can't find the type of variable.
        }
}
like image 691
asharajay Avatar asked Dec 05 '25 10:12

asharajay


1 Answers

Define your class as bellow:

public partial class LinqGrid<T> : UserControl where T : class, new()
{
        System.Data.Linq.Table<T> tmpDataTable;
        public LinqGrid()
        {
            InitializeComponent();
        }
        public void Bind(System.Data.Linq.Table<T> listSource)
        {          
            Project.dbClassesDataContext dbc = new Project.dbClassesDataContext();
            tmpDataTable = listSource;
            var query = (from c in listSource select c);
            dgvRecords.DataSource = query.Take(10).ToList();
        }
        private void btnNext_Click(object sender, EventArgs e)
        {
            tmpDataTable.Skip(10).Take(10); ....
        }
   }
like image 109
Saeed Amiri Avatar answered Dec 07 '25 00:12

Saeed Amiri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!