private void cmdsearch_Click(object sender, EventArgs e) { try { ProductServiceTable service = new ProductServiceTable(); DataTable table = service.searchByProductName(txtSearch.Text.Trim()); DataSet ds = new DataSet(); ds.Tables.Add(table); if (table.Rows.Count != 0) { panel1.Visible = true; dataGrid2.DataSource = ds.Tables["Products"]; TotalRecord = ds.Tables["Products"].Rows.Count; double tmpPageCount = (double)TotalRecord / PageSize; PageCount = Convert.ToInt32(Math.Ceiling(tmpPageCount)); // tsRecordCount.Text = TotalRecord.ToString() + " รายการ"; CurrentPage = 1; RecordToDisplay = 0; ShowRecord(CurrentPage); FormatDgvProduct("Products2"); lbltotal.Visible = true; lbltotal.Text = "จำนวนที่ค้นพบ :" + table.Rows.Count + " รายการ"; } else { panel1.Visible = false; DataTable tablenull = new DataTable("Products"); DataSet dsnull = new DataSet(); dataGrid1.DataSource = dsnull.Tables["Products"]; lbltotal.Visible = true; lbltotal.Text = "จำนวนที่ค้นพบ : " + tablenull.Rows.Count + " รายการ"; } } catch (Exception ex) { Console.WriteLine(ex.Message); } }